Software Design: CPE 223L
Software Design: CPE 223L
Software Design: CPE 223L
CPE 223L
Software design
• Software design is the process by which an agent
creates a specification of a software artifact
intended to accomplish goals, using a set of
primitive components and subject to constraints.
VB.Net
• Visual Basic .NET (VB.NET) is an object-oriented
computer programming language implemented
on the .NET Framework.
• Like all other .NET languages, VB.NET has
complete support for object-oriented concepts.
Everything in VB.NET is an object, including all of
the primitive types (Short, Integer, Long, String,
Boolean, etc.) and user-defined types, events, and
even assemblies. All objects inherits from the
base class Object.
Basic Syntax
• Object − Objects have states and behaviors. An object is an
instance of a class.
• Class − A class can be defined as a template/blueprint that
describes the behaviors/states that objects of its type
support.
• Methods − A method is basically a behavior. A class can
contain many methods. It is in methods where the logics are
written, data is manipulated and all the actions are executed.
• Instance Variables − Each object has its unique set of
instance variables. An object's state is created by the values
assigned to these instance variables.
Identifiers
• An identifier is a name used to identify a class,
variable, function, or any other user-defined item.
The basic rules for naming classes in VB.Net are
as follows −
• A name must begin with a letter that could be followed
by a sequence of letters, digits (0 - 9) or underscore.
The first character in an identifier cannot be a digit.
• It must not contain any embedded space or symbol
like ? - +! @ # % ^ & * ( ) [ ] { } . ; : " ' / and \. However,
an underscore ( _ ) can be used.
• It should not be a reserved keyword.
Data Types
• It refers to an extensive system used for declaring
variables or functions of different types. The type
of a variable determines how much space it
occupies in storage and how the bit pattern
stored is interpreted.
Data Types
Boolean Byte Char
Date Decimal Double
Integer Long Object
Sbyte Short Single
String Uinteger Ulong
UShort
The Type Conversion Functions in
VB.Net
• CBool(expression) - Converts the expression to
Boolean data type.
• CByte(expression) - Converts the expression to
Byte data type.
• CChar(expression) - Converts the expression to
Char data type.
• CDate(expression) - Converts the expression to
Date data type
The Type Conversion Functions in
VB.Net
• CDbl(expression) - Converts the expression to
Double data type.
• CDec(expression) - Converts the expression to
Decimal data type.
• CInt(expression) - Converts the expression to
Integer data type.
• CLng(expression) - Converts the expression to
Long data type.
Variables
• A variable is nothing but a name given to a
storage area that our programs can manipulate.
Each variable in VB.Net has a specific type, which
determines the size and layout of the variable's
memory; the range of values that can be stored
within that memory; and the set of operations
that can be applied to the variable.
Variables
Type Example
Integral types SByte, Byte, Short, UShort,
Integer, UInteger, Long,
ULong and Char
Floating point types Single and Double
Decimal types Decimal
Boolean types True or False values, as
assigned
Date types Date
Variable Declaration
• The Dim statement is used for variable
declaration and storage allocation for one or
more variables. The Dim statement is used at
module, class, structure, procedure or block level.
Variable Declaration
• Syntax for variable declaration in VB.Net is −
[ < attributelist > ] [ accessmodifier ] [[ Shared ]
[ Shadows ] | [ Static ]] [ ReadOnly ] Dim
[ WithEvents ] variablelist
Variable Declaration
• attributelist is a list of attributes that apply to the variable. Optional.
• accessmodifier defines the access levels of the variables, it has values as -
Public, Protected, Friend, Protected Friend and Private. Optional.
• Shared declares a shared variable, which is not associated with any specific
instance of a class or structure, rather available to all the instances of the class
or structure. Optional.
• Shadows indicate that the variable re-declares and hides an identically named
element, or set of overloaded elements, in a base class. Optional.
• Static indicates that the variable will retain its value, even when the after
termination of the procedure in which it is declared. Optional.
• ReadOnly means the variable can be read, but not written. Optional.
• WithEvents specifies that the variable is used to respond to events raised by
the instance assigned to the variable. Optional.
• Variablelist provides the list of variables declared.
Variable Declaration
• Each variable in the variable list has the following
syntax and parts −
• variablename − is the name of the variable
• boundslist − optional. It provides list of bounds of each
dimension of an array variable.
• New − optional. It creates a new instance of the class when
the Dim statement runs.
• datatype − Required if Option Strict is On. It specifies the
data type of the variable.
• initializer − Optional if New is not specified. Expression
that is evaluated and assigned to the variable when it is
created.
Variable Declaration Example
• Dim StudentID As Integer
• Dim StudentName As String
• Dim Salary As Double
• Dim count1, count2 As Integer
• Dim status As Boolean
• Dim exitButton As New
System.Windows.Forms.Button
• Dim lastTime, nextTime As Date
Variable Initialization
• Variables are initialized (assigned a value) with an
equal sign followed by a constant expression. The
general form of initialization is −
• variable_name = value;
• Example:
• Dim pi As Double
• pi = 3.14159
• Dim StudentID As Integer = 100
• Dim StudentName As String = "Bill Smith“
Accepting Values from User
• The Console class in the System namespace
provides a function ReadLine for accepting input
from the user and store it into a variable. For
example:
• Dim message As String
• message = Console.ReadLine
Accepting Values from User
Module variablesNdataypes
Sub Main()
Dim message As String
Console.Write("Enter message: ")
message = Console.ReadLine
Console.WriteLine()
Console.WriteLine("Your Message: {0}", message)
Console.ReadLine()
End Sub
End Module
Decision Making
• If...Then statement consists of a boolean
expression followed by one or more statements.
If (a <= 20) Then
c= c+1
End If
Decision Making
• If...Then statement can be followed by an optional Else
statement, which executes when the boolean expression is
false.
If (a < 20) Then
' if condition is true then print the following
Console.WriteLine("a is less than 20")
Else
' if condition is false then print the following
Console.WriteLine("a is not less than 20")
End If
Loops
• Do Loops
Do
Console.WriteLine("value of a: {0}", a)
a=a+1
Loop While (a < 20)
Loops
• For...Next Loop
For a = 10 To 20
Console.WriteLine("value of a: {0}", a)
Next
Loops
• Each...Next Loop
For Each arrayItem In anArray
Console.WriteLine(arrayItem)
Next
Loops
• While... End While Loop
While a < 20
Console.WriteLine("value of a: {0}", a)
a=a+1
End While
Loops
• Exit Statement
While (a < 20)
Console.WriteLine("value of a: {0}", a)
a=a+1
If (a > 15) Then
'terminate the loop using exit statement
Exit While
End If
End While
Loops
• Continue Statement
Do
If (a = 15) Then
' skip the iteration '
a=a+1
Continue Do
End If
Console.WriteLine("value of a: {0}", a)
a=a+1
Loop While (a < 20)
DEVELOPING CLASSES
• One of the primary uses of OOP is to develop
user-defined data types.
• To aid our discussion, and to illustrate some of the
fundamental principles of OOP, we will develop
two classes for describing one or two features of
a geometric data processing system: the Point
class and the Circle class.
Data Members and Constructors
• The data defined in a class, generally, are meant to
stay hidden within the class definition.
• This is part of the principle of encapsulation. The
data stored in a class are called data members, or
alternatively, fields.
• To keep the data in a class hidden, data members
are usually declared with the Private access
modifier.
• Data declared like this cannot be accessed by user
code.
Data Members and Constructors
• The Point class will store two pieces of data—the
x coordinate and the y coordinate. Here are the
declarations for these data members:
Data Members and Constructors
• When a new class object is declared, a constructor
method should be called to perform any initialization
that is necessary.
• Constructors in VB.NET are named New by default,
unlike in other languages where constructor methods
are named the same as the class.
• Constructors can be written with or without arguments.
A constructor with no arguments is called the default
constructor.
• A constructor with arguments is called a parameterized
constructor.
Data Members and Constructors
Property Methods
• A Property method provides the ability to both
set and retrieve the value of a data member
within the same method definition.
• This is accomplished by utilizing a Get clause and
a Set clause.
Property Methods
Other Methods
• Of course, constructor methods and Property
methods aren’t the only methods we will need in
a class definition.
• One method included in all well-defined classes is
a ToString method, which returns the current
state of an object by building a string that consists
of the data member’s values.
Other Methods
• Here’s the ToString method for the Point class:
Other Methods
• Notice that the ToString method includes the
modifier Overrides.
• This modifier is necessary because all classes
inherit from the Object class and this class already
has a ToString method.
• For the compiler to keep the methods straight,
the Overrides modifier indicates that, when the
compiler is working with a Point object, it should
use the Point class definition of ToString and not
the Object class definition.
Other Methods
• One additional method many classes include is
one to test whether two objects of the same class
are equal. Here is the Point class method to test
for equality:
Inheritance and Composition
• The ability to use an existing class as the basis for
one or more new classes is one of the most
powerful features of OOP.
• There are two major ways to use an existing class
in the definition of a new class:
• The new class can be considered a subclass of the
existing class (inheritance).
• The new class can be considered as at least partially
made up of parts of an existing class (composition).
Inheritance and Composition
• For example, we can make a Circle class using a
Point class object to determine the center of the
circle.
• Since all the methods of the Point class are
already defined, we can reuse the code by
declaring the Circle class to be a derived class of
the Point class, which is called the base class.
• A derived class inherits all the code in the base
class plus it can create its own definitions.
Inheritance and Composition
• The Circle class includes both the definition of a
point (x and y coordinates) as well as other data
members and methods that define a circle (such
as the radius and the area). Here is the definition
of the Circle class:
Inheritance and Composition
Inheritance and Composition
Inheritance and Composition
• There are a couple of features in this definition
you haven’t seen before.
• First, the parameterized constructor call includes
the following line:
• This is a call to the constructor for the base class
(the Point class) that matches the parameter list.
• Every derived class constructor must include a call
to one of the base classes’ constructors.
COLLECTIONS DEFINED
• A collection is a structured data type that stores
data and provides operations for adding data to
the collection, removing data from the collection,
updating data in the collection, and setting and
returning the values of different attributes of the
collection.
COLLECTIONS DEFINED
• Collections can be broken down into two types:
• A linear collection is a list of elements where one
element follows the previous element.
• Nonlinear collections hold elements that do not have
positional order within the collection.
COLLECTIONS DESCRIBED
• Linear collections can be either direct access
collections or sequential access collections.
• Whereas nonlinear collections can be either
hierarchical or grouped.
Direct Access Collections
• The most common example of a direct access
collection is the array. We define an array as a
collection of elements with the same data type
that are directly accessed via an integer index.
Direct Access Collections
• Another type of direct access collection is the
string. A string is a collection of characters that
can be accessed based on their index, in the same
manner we access the elements of an array.
• Strings are also implemented as class objects in
VB.NET.
Direct Access Collections
• The final direct access collection type is the
structure, known as a userdefined type in Visual
Basic 6.
• A structure is a composite data type that holds
data that may consist of many different data
types.
Direct Access Collections
• A powerful addition to the VB.NET structure is the
ability to define methods for performing
operations stored on the data in a structure. This
makes a structure quite like a class, though you
can’t inherit from a structure.
Direct Access Collections
Sequential Access Collections
• A sequential access collection is a list that stores
its elements in sequential order. We call this type
of collection a linear list.
• Linear lists are not limited by size when they are
created, meaning they are able to expand and
contract dynamically.
• Items in a linear list are not accessed directly;
they are referenced by their position,
Sequential Access Collections
• A sequential access collection is a list that stores
its elements in sequential order. We call this type
of collection a linear list.
• Linear lists are not limited by size when they are
created, meaning they are able to expand and
contract dynamically.
• Items in a linear list are not accessed directly;
they are referenced by their position,
Sequential Access Collections
• Stack is a list where access is restricted to the
beginning (or top) of the list. Items are placed on
the list at the top and can only be removed from
the top. For this reason, stacks are known as Last-
In, First-Out structures.
Sequential Access Collections
• A queue is a list where items are added at the
rear of the list and removed from the front of the
list.
• This type of list is known as a First-In, First-Out
structure.
Hierarchical Collections
• Nonlinear collections are broken down into two
major groups:
• Hierarchical Collections
• Group Collections.
Hierarchical Collections
• A hierarchical collection is a group of items
divided into levels. An item at one level can have
successor items located at the next lower level.
• One common hierarchical collection is the tree. A
tree collection looks like an upside-down tree,
with one data element as the root and the other
data values hanging below the root as leaves.
Hierarchical Collections
• The file systems of most modern operating
systems are designed as a tree collection, with
one directory as the root and other subdirectories
as children of the root.
Group Collections
• A nonlinear collection of items that are unordered
is called a group. The three major categories of
group collections are sets, graphs, and networks.
• A set is a collection of unordered data values
where each value is unique. The list of students in
a class is an example of a set, as is, of course, the
integers.
• Operations that can be performed on sets include
union and intersection.
Group Collections
THE VB.NET COLLECTION CLASS
• The VB.NET Framework library includes a generic
collection class for storing data. The class includes
two methods and two properties for adding,
removing, retrieving, and determining the
number of items in the collection.
Adding Data to a Collection
• The Add method is used to store data in a
collection. In its simplest form, the method takes
just one argument, a data item to store in the
collection.
Adding Data to a Collection
• Another way to add data to a collection is to also
store keys along with the data.
Adding Data to a Collection
• Collection items are retrieved with the Item
method. Items can be retrieved either by their
index or by a key, if one was specified when the
item was added. Using the index and the Count
property, we can return each item from a
collection using a For loop as follows:
Arrays and ArrayLists
• The array is the most common data structure and
is found in nearly all computer programming
languages.
• A new feature in VB.NET is the ArrayList class. An
ArrayList is an array that grows dynamically as
more space is needed.
ARRAY BASICS
• An array stores a set of elements ordered by
position. The base position, or index, of arrays in
VB.NET is zero.
Declaring and Initializing Arrays
Setting and Accessing Array Elements
• Elements are stored in an array either by direct
access or by calling the Array class method
SetValue.
• Direct access involves referencing an array position by
index on the left-hand side of an assignment statement:
• Database
– A collection of related data stored in a manner that
enables information to be retrieved as needed
• Database Management System (DBMS)
– Used to create, maintain, and access databases
– Database engine
• The part of the program that actually stores and
retrieves data
– Microsoft Access, OpenOffice Base, Corel Paradox, Oracle
Database, etc.
– Primary Key
• Field that uniquely identifies the records in a table
• Field in a table that is used to relate that table to other
tables
– Database Administrators
• Responsible for managing the databases within an
organization
– Users
• Individuals who enter data, update data, and retrieve
information from the database
• Data Hierarchy
– Fields/columns
• Hold single pieces of data
– Records/rows
• Groups of related fields
– Tables
• Collection of related records
– Database
• Contains a group of related tables
• Data Definition
– The process of describing the properties of data to be
included in a database table
– During data definition, each field is assigned:
• Name (must be unique within the table)
• Data type (such as Text, Number, Currency, Date/Time)
• Description (optional description of the field)
• Properties (field size, format of the field, allowable
range, if field is required, etc.)
– Finished specifications for a table become the table
structure
• Data Integrity
– Accuracy of Data
• Quality of data entered determines the quality of
generated information
– Data Validation
• Process of ensuring that data entered into the database
is valid
• Record validation rules
– Checks all fields before changes to a record
are saved
• Can be enforced on a per transaction basis so the entire
transaction will fail if one part is invalid
Understanding Computers: Today and Tomorrow, 15th Edition 10
9
Data Integrity, Security, and Privacy
– Database Locking
• Prevents two individuals from changing the same data
at the same time
• Data Security
– Protects data against destruction and misuse
– Protects against unauthorized access to and unauthorized
use of a database
– Database activity monitoring programs can be used to
detect possible intrusions and risks
– Prevents data loss
– Should include strict backup and disaster-recovery
procedures (disaster-recovery plan)
– Should be used with both in-house and cloud databases
– Data Privacy
• Growing concern because of the vast amounts of
personal data stored in databases today
• Many states require businesses to notify customers
when their personal data has been compromised
• Data breaches can be costly
– One estimate is $200 per breached record
• Data Organization
– Arranging data for efficient retrieval
– Indexed organization
• Uses an index to keep track of where data is stored in a
database
• Direct Organization
– Uses hashing algorithms to specify the exact storage
location
– Algorithms should be
designed to limit collisions
– Some systems use a combination of both
indexed and direct organization
Understanding Computers: Today and Tomorrow, 15th Edition 11
4
Data Organization
Column Databases
– Stores data by columns
instead of rows
– Improves performance
by minimizing the
time needed to read
the disk
– Used with data
warehouses and other
big data applications
Answers:
1) a; 2) True; 3) data dictionary
Answers:
1) a; 2) True; 3) centralized
Understanding Computers: Today and Tomorrow, 15th Edition 12
5
Introduction to SQL
• What is SQL?
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
• SQL became a standard of the American National
Standards Institute (ANSI) in 1986, and of the
International Organization for Standardization (ISO) in
1987
Introduction to SQL
• What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create stored procedures in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures, and views
Introduction to SQL
• SQL is a Standard - BUT....
• Although SQL is an ANSI/ISO standard, there are
different versions of the SQL language.
• However, to be compliant with the ANSI standard, they
all support at least the major commands (such as
SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar
manner.
SQL Syntax
• Database Tables
• A database most often contains one or more tables.
Each table is identified by a name (e.g. "Customers" or
"Orders"). Tables contain records (rows) with data.
SQL SELECT Statement
• The SELECT statement is used to select data from
a database.
• The data returned is stored in a result table,
called the result-set.
• Here, column1, column2, ... are the field names of
the table you want to select data from.