Title: Object Oriented System Development with VB .NET
1Chapter 1
- Object Oriented System Development with VB .NET
2Introduction
- Object-oriented information system development
involves analysis, design, and implementation of
information systems using - Object-oriented programming languages
- Object-oriented technologies
- Object-oriented techniques
- Object-oriented information system development is
usually referred to as OO or as the OO
approach
3Introduction
- When developing business systems, OO means using
an - Object-oriented approach to system analysis (OOA)
- Object-oriented approach to system design (OOD)
- Object-oriented approach to programming (OOP)
4Understanding OO Development and VB .NET
- The object-oriented approach defines a system as
a collection of objects that work together to
accomplish tasks - The objects can carry out actions when asked
- Each object maintains its own data
5Understanding OO Development and VB .NET
- The procedural approach defines a system as a set
of procedures that interact with data - The data are maintained in files separate from
the procedures - When the procedure executes, data files are
created or updated
6Understanding OO Development and VB .NET
7Object-Oriented Programming
- Object-oriented programming started in the 1960s
- Today many OO programming languages
- Java is a pure OO language
- Microsoft
- C .NET a direct competitor to JAVA
- With VB .NET hopes to dominate OO and Web-based
development
8The Microsoft .NET Framework and VB .NET
- The .NET framework has two main components
- .NET common language runtime (CLR)
- manages code at execution
- Supports variety of programming languages
- All code compiled to MSIL
- .NET framework class library
- reusable classes of objects that work with the
CLR - Any .NET language can use these classes
- VB .NET is a full-blown OO programming language
9Object-Oriented Analysis and Design
- The standard object-oriented analysis and design
modeling notation is - Unified Modeling Language (UML)
- assumes a model-driven approach to analysis and
design
10Object-Oriented Analysis and Design
11Object-Oriented Analysis and Design
- The system development life cycle (SDLC) is a
project management framework - It defines project phases and activities within
phases - The phases typically are named
- Planning
- Analysis
- Design
- Implementation
- Support
12Object-Oriented Analysis and Design
- OO developers usually follow an iterative
approach to analysis, design, and
implementation - Prototyping and joint application development
(JAD) are usually part of OO development - Prototyping creating a working model of one or
more parts of a system to give users a chance to
see and evaluate something concrete - During JAD sessions, key system stakeholders and
decision makers work together to define system
requirements and designs
13Object-Oriented Analysis and Design
- The following are also required when using OO
development, as they are in traditional system
development - Project management
- Interviewing and data collection
- User interface design
- Testing
- Conversion techniques
14Understanding Object-Oriented Concepts
- Object-oriented development assumes that a system
is a collection of objects that interact to
accomplish tasks
15Objects, Attributes, and Methods
- An object (nouns) is a thing that has attributes
(adjectives) and behaviors (verbs) - A GUI object
- uses graphics, such as a button or label
- has attributes (adjectives), which are
characteristics that have values - have behaviors or methods (verbs), which
describe what an object can do
16Objects, Attributes, and Methods
- OO systems also contain problem domain objects
- a business system might use
- Customer objects
- Order objects
- Product objects
- What attributes or methods might be assigned?
- Objects interact by sending messages to each
other - Tasks to be carried out is the main concept of
OOA and OOD
17Encapsulation and Information Hiding
- Encapsulation
- an object has attributes and methods combined
into one unit - programmer does not need to know the internal
structure of the object to send messages to it - Information hiding
- Using encapsulation to hide the internal
structure of objects, protecting them from
corruption
18Encapsulation and Information Hiding
- Each object also has a unique identity
- An objects identity must be known for sending a
message to it - The objects identity is usually stored as a
memory address - Persistent objects are those that are defined as
available for use over time usually stored in a
file system
19Classes, Instances, and Associations
- The class defines
- what all objects of the class represent
- Objects can be referred to as instances of the
class - When an object is created for the class, it is
common to say the class is instantiated - The terms instance and object are often used
interchangeably
20Classes, Instances, and Associations
21Classes, Instances, and Associations
- Objects maintain association relationships among
themselves - Some association relationships are one-to-one,
and some associations are one-to-many - UML refers to the number of associations as the
multiplicity of the association
22Classes, Instances, and Associations
23Inheritance and Polymorphism
- Inheritance
- one class of objects takes on characteristics of
another class and extends them - For example
- Person Generalization - Superclass
- Customer
- Employee
- Student
- All are specialization or SubClasses of Person
- Can extend Person with additional Attributes and
Methods - What might be another example of Inheritance?
24Polymorphism
- Polymorphism
- the way different objects can respond in their
own way to the same message - Classes are polymorphic if their instances can
respond to the same message differently - Example
- Bank Account ComputeInterest Method
- Savings
- Certificate of Deposit
- Checking
25Benefits of OO Development
- The two main reasons
- Naturalness
- people usually think about their world in terms
of objects - OOA, OOD, and OOP all involve modeling classes of
objects - Reuse
- Classes and objects can be invented once and used
many times - class libraries that contain predefined classes
- Programmers use these classes to create their own
objects
26Introducing Three-Tier Design
- The book is organized according to an approach to
OO development called three-tier design - Three-tier design requires
- GUI classes Presentation Presentation Tier
- Problem domain classes Business Rules
Business Tier - Data access classes Data Data Tier
27Part 1 Object-Orientation and VB .NET
Fundamentals
- Part 1 covers OO concepts and introduces the VB
.NET programming language - This part includes chapters 1, 2, 3, 4 and 5
28Part 2 Developing Problem Domain Classes
- Part 2 shows how to use VB .NET to create new
problem domain classes that are specific to the
business system being developed - Part 2 includes chapters 6, 7, 8 and 9
29Part 3 Developing GUI Classes
- Part 3 describes how to create graphical user
interface classes with which the user can
interact - The GUI classes in turn interact with problem
domain classes - Part 3 includes chapters 10, 11 and 12
30(No Transcript)
31Chapter 2
- The Visual Studio .NET Development Environment
32Visual Studio .NET
- Visual Studio .NET is
- Integrated Development Environment (IDE) used to
- Create .NET projects
- Compile and execute programs
- Design GUI front ends (forms)
- Debug programming logic
- Contains extensive help facilities
- Dynamic help
- Context-sensitive help F1
- IntelliSense
33Understanding the Start Page
34Creating a Project Using VB .NET
- To create a VB .NET project, identify
- Type of project
- Template to use
- a pattern for creating a specific type of
application - Project name and location
- Project Name must be meaningful
- Customize this location
35Understanding the Way VB .NET Organizes Your
Programs
- A project (.vbproj) is a mechanism for grouping
related files, for example - Program files (.vb)
- Image files
- Other miscellaneous items
- Startup object must be set
- A solution (.sln) is a container for one or more
projects - Solution file appears at the top of the hierarchy
in Solution Explorer window - Startup project must be set
36Using the Text Editor
- Visual Studio .NET text editor provides
- Standard text editing capabilities
- Color-coding feature
- VB Specific
- Pretty Print
- Code indentation feature
- Code completion feature
37Setting the Startup Object
- After changing the module name within the source
code, project properties must be changed to
identify the new name as the startup object - Startup object is the module where execution
begins
38Compiling and Executing a VB .NET Program
- A program can be compiled and executed using
- Options on Build and Debug menus or toolbars
- Shortcut key combinations
- To compile and execute a program using menu
options - Click Debug on menu bar
- Click Start Without Debugging
39Using the Visual Form Designer
- A Windows application is one that runs in the
Windows environment - When creating Windows applications, a visual form
editor can be used - In a visual editor
- Programmer places icons representing various
components on the screen - VB .NET generates required programming statements
40Using the Visual Form Designer
- The visual form editor in MDE is Windows Forms
Designer - Toolbox contains visual components
- Elements can be selected from Toolbox to
dynamically design forms - Properties window is used to adjust properties of
components on the form
41Creating a Windows Application
42Customizing the Appearance of a Form
- To change title of the form, use Text property in
Properties window
43Adding Components to a Form
- Toolbox contains components which can be added to
a form
44Accessing Help
- Most help features can be accessed through
options on Help menu
45Chapter 3
- VB .NET Programming Fundamentals
46Writing a VB .NET Module Definition
- VB .NET code can be structured as a module
definition, form definition, or class definition - Module definition begins with Module and ends
with End Module - Form definition is used to create a GUI
- Class definition is written to represent an
object
47Writing a VB .NET Module Definition
- The VB .NET statements consist of keywords and
identifiers - VB .NET identifiers
- Can be of any length
- Can include any letter or number, but no spaces
- Must begin with a letter of the alphabet
- VB .NET code is not case sensitive
- Naming Conventions
- Camel Casing
- Comment lines
- Begin with a single quote (')
48Writing a VB .NET Module Definition
- Procedures
- begin with a procedure header
- identifies the procedure
- describes some of its characteristics
- VB .NET has two types of procedures
- Function
- A Function procedure can return a value
- Sub
- A Sub procedure cannot return a value
49Using VB. NET Variables and Data Types
- A variable named memory location that can
contain data - All variables have
- Data type kind of data the variable can contain
- Name An identifier the programmer creates to
refer to the variable - Value Every variable refers to a memory
location that contains data. This value can be
specified by the programmer
50Declaring and Initializing Variables
- When declaring a variable, the programmer must
specify its data type - VB .NET has nine primitive data types
- Data types for numeric data without decimals
- Byte, Short, Integer, Long
- Data types for numeric data with decimals
- Single, Double, Decimal
- Other data types
- Boolean, Char
51Declaring and Initializing Variables
- To declare a VB .NET variable, write
- Keyword Dim
- Name to be used for identifier
- Keyword As
- Data type
- Example
- ' declare a variableDim i As Integer
52Declaring and Initializing Variables
- A value can be assigned by the programmer to a
variable - Assignment operator () assigns the value on the
right to the variable named on the left side - Example
- ' populate the variable
- i 1
53Changing Data Types
- If Option Strict On
- helps prevent unintentional loss of precision
- Casting from one data type to another must be
done Explicitly - If Option Explicit On
- the programmer must define a variable before
using it in a statement - Required in all programs
54Using Constants
- Constant variable with a value that does not
change - Code to declare a constant is identical to the
code to declare a variable, except - Keyword Const is used instead of Dim
- Constants must be initialized in the statement
that declares them - By convention, constant names are capitalized
EX. Const SALES_TAX_RATE As Decimal 0.075
55Using Reference Variables
- There are two kinds of variables
- Primitive variable
- Declared with a primitive data type
- Contains the data the programmer puts there
- Reference variable
- Uses a class name as a data type
- Refers to or points to an instance of that class
- Does not contain the data
- Contains the address of an instance of a class
that contains the data
56Using Reference Variables
57Computing with VB .NET
- VB .NET uses
- Arithmetic operators (, , , /) for addition,
subtraction, multiplication, and division - Remainder operator (Mod) produces a remainder
resulting from the division of two integers - Integer division operator (\) to produce an
integer result - Caret () for exponentiation
- String concatenation operator
58Order of Operations
- Parenthesis
- Exponents
- Multiplication / Division
- Integer Division
- Modulus
- Addition / Subtraction
59Assignment Operators
- , -, , / , \, intTotal intTotal
intStudentScore - Can be written
- intTotal intStudentScore
60Computing with VB .NET
- Math class contains methods to accomplish
exponentiation, rounding, and other tasks - To invoke a Math class method, write
- Name of the class (Math)
- A period
- Name of the method
- Any required arguments
- Example Math.Pow(5,4)
61Writing Decision-Making Statements
- Selection statements evaluate conditions and
execute statements based on that evaluation - VB .NET includes If and Select Case statements
- If statement
- Evaluates an expression
- Executes one or more statements if expression is
true - Can execute another statement or group of
statements if expression is false
62Writing Decision-Making Statements
- Select Case statement
- Evaluates a variable for multiple values
- Executes a statement or group of statements,
depending on contents of the variable being
evaluated
63Writing If Statements
64Writing If Statements
- VB .NET If statement has two forms Simple If and
If-Else - Simple If
- Evaluates an expression
- Executes one or more statements if expression is
true - If expressions then statement(s)End If
65Writing If Statements
- If-Else
- If expression Then statements
- Else
- statements
- End If
66Logical Operators
- AND
- OR
- NOT
- If (intAge gt 20) And (intAge lt 35) then
- statements
- End if
- .NET will short circuit conditional testing as
soon as it can determine result
67Nested IFs
If intAge gt 20 Then If intAge lt 35
Then statements
Else statements End If Else
statementsEnd If
68Writing Select Case Statements
- Select Case statement
- Acts like a multiple-way If statement
- Transfers control to one of several statements,
depending on the value of an expression - Select intStudentAgeCase is gt 21
statements - Case 17 to 18
- statements
- Case 10,12,14
- statementsCase Else
- statements
- End Select
69Writing Loops
- Loops repeated execution of one or more
statements until a terminating condition occurs - Three types of loops
- Do While (condition is true) While (condition
is true) - statements
statements - Loop
End While - Do Until (until condition is true)
- statements
- Loop
- For Next
- Early out
- Exit Do, Exit For, Exit While
70Writing Post-Test Loops
- Programming languages provide two kinds of loops
- Pre-test loop tests the terminating condition at
the beginning of the loop - Post-test loop tests the terminating condition at
the end of the loop
71Writing Post-Test Loops
- Do
- statements
- Loop While (condition is true)
- Do
- statements
- Loop Until (condition becomes true)
- For Next and While loops are always pre-test
72Writing For Next Loops
- VB .NET For Next loop
- loop counter
- initialization
- incrementing defaults to 1, can be any /-
value - pre-test logic Example
- ' for next loop
- For i 1 To 3 Step 1
- Console.WriteLine("for next loop i " i)
- Next
73Writing Nested Loops
- Nested loop
- A loop within a loop
- Can be constructed using any combination of Do
While, Do Until, or For Next loops
74Declaring and Accessing Arrays
- Arrays create a group of variables with the same
data type - In an array
- Each element behaves like a variable
- All elements must have the same data type
- Elements either can contain primitive data or can
be reference variables
75Declaring and Accessing Arrays
- Arrays can be either one-dimensional or
multi-dimensional - One-dimensional array consists of elements
arranged in a row - Two-dimensional array has both rows and columns
- Three-dimensional array has rows, columns, and
pages - VB .NET implements multi-dimensional arrays as
arrays of arrays
76Using One-Dimensional Arrays
- Declare a 5-element array with of integers
- ' declare an integer array with 5 elements
- Dim intTestScores(4) As Integer
- Accessing individual array elements intTestScores
(0) - Subscript (Index) must be an integer
- Literal - (1)
- Identifier (intCounter)
- Relative reference (intCounter 2)
- Expression (intAge intMultiplier)
- Length attribute returns number of elements
77Using One-Dimensional Arrays
- Code to initialize the array elements
- testScores(0) 75
- testScores(1) 80testScores(2)
70testScores(3) 85testScores(4) 90 - An array can be declared and populated using a
single statement - Dim testScores() As Integer 75, 80, 70, 85,
90
78Using One-Dimensional Arrays
79Using Multidimensional Arrays
- Conceptually
- A two-dimensional array is like a table with rows
and columns - A three-dimensional array is like a cube, with
rows, columns, and pages - Each dimension has its own index
- Declare an Integer array with five rows and two
columns - Dim testScoreTable(4, 1) As Integer
- Length attribute returns total number of
elements Example testScoreTable.Length returns
10 - GetLength(dimension) returns the number of
elements in a specific dimensionExample
testScoreTable.GetLength(0) returns 5
80Using Multidimensional Arrays
81(No Transcript)