Download presentation
Presentation is loading. Please wait.
1
Object Oriented System Development with VB .NET
Chapter 1 Object Oriented System Development with VB .NET Object-Oriented Application Development Using VB .NET
2
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Learn about OO development and VB .NET Understand object-oriented concepts Recognize the benefits of OO development Preview the approach this book uses to teach you OO development Object-Oriented Application Development Using VB .NET
3
Object-Oriented Application Development Using VB .NET
Valued Gateway Client: Introduction 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” Object-Oriented Application Development Using VB .NET
4
Object-Oriented Application Development Using VB .NET
Introduction 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) Object-Oriented Application Development Using VB .NET
5
Understanding 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 Object-Oriented Application Development Using VB .NET
6
Understanding 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 Object-Oriented Application Development Using VB .NET
7
Understanding OO Development and VB .NET
Object-Oriented Application Development Using VB .NET
8
Object-Oriented Programming
Object-oriented programming started in the 1960s with the development of the Simula programming language A major milestone in the history of OO was the development of the SmallTalk programming language in the early 1970s Additional object-oriented programming languages include Objective-C, Eiffel, and most notably C++ Object-Oriented Application Development Using VB .NET
9
Object-Oriented Programming
In 1995, Sun Microsystems introduced Java as a pure OO language, which has: Syntax similar to C++ Features that make it appropriate for Internet applications Microsoft immediately released a version of Java called J++ Object-Oriented Application Development Using VB .NET
10
Object-Oriented Programming
Microsoft recently released a more direct competitor to Java as part of the .NET framework, named C# With the release of VB .NET, Microsoft hopes to dominate OO and Web-based development Object-Oriented Application Development Using VB .NET
11
The Microsoft .NET Framework and VB .NET
The .NET framework has two main components: .NET common language runtime .NET framework class library The .NET Common Language Runtime (CLR) manages code at execution Developers can use a variety of programming languages that the CLR environment can compile and execute Object-Oriented Application Development Using VB .NET
12
The Microsoft .NET Framework and VB .NET
The .NET framework class library provides reusable classes of objects that work with the CLR A programmer using any of the .NET programming languages can use these classes VB .NET is a full-blown OO programming language that shares the common language runtime and .NET framework class library with the other .NET languages Object-Oriented Application Development Using VB .NET
13
Object-Oriented Analysis and Design
The standard object-oriented analysis and design modeling notation is the Unified Modeling Language (UML) UML assumes a model-driven approach to analysis and design Object-Oriented Application Development Using VB .NET
14
Object-Oriented Analysis and Design
Object-Oriented Application Development Using VB .NET
15
Object-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 Object-Oriented Application Development Using VB .NET
16
Object-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 Object-Oriented Application Development Using VB .NET
17
Object-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 Object-Oriented Application Development Using VB .NET
18
Understanding Object-Oriented Concepts
Object-oriented development assumes that a system is a collection of objects that interact to accomplish tasks Object-Oriented Application Development Using VB .NET
19
Objects, Attributes, and Methods
An object is a thing that has attributes and behaviors A GUI object uses graphics, such as a button or label, to represent part of a system A GUI object has attributes, which are characteristics that have values size, shape, color, location, … GUI objects also have behaviors or methods, which describe what an object can do Object-Oriented Application Development Using VB .NET
20
Objects, Attributes, and Methods
OO systems also contain problem domain objects, which are specific to a business application For example: a business system that processes orders includes: Customer objects Order objects Product objects Problem domain objects also have attributes and methods Object-Oriented Application Development Using VB .NET
21
Object Interactions and Messages
Objects interact by sending messages to each other, asking another object to invoke, or carry out, one of its methods Objects interacting by sending messages to carry out tasks is the main concept of OOA and OOD Object-Oriented Application Development Using VB .NET
22
Encapsulation and Information Hiding
Encapsulation: an object has attributes and methods combined into one unit By combining attributes and methods, the 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 Object-Oriented Application Development Using VB .NET
23
Encapsulation and Information Hiding
Each object also has a unique identity An object’s identity must be known for sending a message to it The object’s identity is usually stored as a memory address Persistent objects are those that are defined as available for use over time Object-Oriented Application Development Using VB .NET
24
Classes, 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 Object-Oriented Application Development Using VB .NET
25
Classes, Instances, and Associations
Object-Oriented Application Development Using VB .NET
26
Classes, 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 Object-Oriented Application Development Using VB .NET
27
Classes, Instances, and Associations
Object-Oriented Application Development Using VB .NET
28
Inheritance and Polymorphism
In inheritance, one class of objects takes on characteristics of another class and extends them For example: An object belonging to the Customer class might also be something more general, such as a person If the Person class is already defined, the Customer class can be defined by extending the Person class to take on more specific attributes and methods required of a customer Object-Oriented Application Development Using VB .NET
29
Inheritance and Polymorphism
In the previous example: The Person class is a superclass The Customer class is the subclass Object-Oriented Application Development Using VB .NET
30
Inheritance and Polymorphism
The result of extending general classes into more specific subclasses is referred to as a generalization/specialization hierarchy It is also called an inheritance hierarchy 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 Object-Oriented Application Development Using VB .NET
31
Recognizing the Benefits of OO Development
The two main reasons why the object-oriented approach is being used in information system development are: Naturalness Reuse Object-Oriented Application Development Using VB .NET
32
Objects Are More Natural
Naturalness: people usually think about their world in terms of objects When people discuss system requirements, it is natural to define the classes of objects involved OOA, OOD, and OOP all involve modeling classes of objects – so the focus remains on objects throughout the development process Object-Oriented Application Development Using VB .NET
33
Classes of Objects Can Be Reused
The ability to reuse classes and objects is an important benefit of object-oriented development Classes and objects can be invented once and used many times Object-oriented programming languages come with class libraries that contain predefined classes most programmers need Programmers use these classes to create their own objects Object-Oriented Application Development Using VB .NET
34
Learning OO Development
This book provides a comprehensive guide to OO system development, including OOA, OOD, and OOP Object-Oriented Application Development Using VB .NET
35
Introducing Three-Tier Design
The book is organized according to an approach to OO development called three-tier design Three-tier design requires that the collection of objects that interact in an OO system be separated into three categories of classes: Problem domain classes GUI classes Data access classes Object-Oriented Application Development Using VB .NET
36
Introducing Three-Tier Design
Problem domain classes are the classes of objects specific to the business application GUI classes define the objects that make up the user interface to the application Data access classes work with the database management system to store information about objects for later use The core of this book is organized according to the three tiers of OO development Object-Oriented Application Development Using VB .NET
37
Part 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 Object-Oriented Application Development Using VB .NET
38
Part 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 Object-Oriented Application Development Using VB .NET
39
Part 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 Object-Oriented Application Development Using VB .NET
40
Part 4: Developing Data Access Classes
Part 4 covers the third tier—data access classes Data access classes are used to manage database interactions and achieve object persistence Part 4 includes chapters 13 and 14 Object-Oriented Application Development Using VB .NET
41
Part 5: Deploying the Three-Tier Application
Part 5 shows how GUI classes, problem domain classes, and data access classes function together as three tiers to create a complete client-server system Part 5 includes chapters 15 and 16 Object-Oriented Application Development Using VB .NET
42
Object-Oriented Application Development Using VB .NET
Summary Object-oriented information system development includes object-oriented analysis (OOA), object-oriented design (OOD), and object-oriented programming (OOP) Object-oriented (OO) systems are viewed as collections of interacting objects that accomplish tasks The Microsoft .NET framework is a computing platform that simplifies development of OO applications Object-Oriented Application Development Using VB .NET
43
Object-Oriented Application Development Using VB .NET
Summary A model-driven approach using UML diagrams defines requirements and designs prior to programming The benefits of OO development include naturalness and reuse This text is organized into five parts and explains the three-tier design approach to OO development Object-Oriented Application Development Using VB .NET
44
The Visual Studio .NET Development Environment
Chapter 2 The Visual Studio .NET Development Environment Object-Oriented Application Development Using VB .NET
45
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Explore the Visual Studio .NET development environment Create a project using Visual Basic .NET Compile and execute a VB .NET program Use the visual form designer Explore the debugging tool Explore the help facility Object-Oriented Application Development Using VB .NET
46
Exploring the Visual Studio .NET Development Environment
Valued Gateway Client: Exploring the Visual Studio .NET Development Environment VB .NET is a language supported by Microsoft’s Visual Studio .NET integrated development environment Integrated development environment (IDE) helps programmers code, test, and document programs Object-Oriented Application Development Using VB .NET
47
Exploring the Visual Studio .NET Development Environment
Makes it easy to organize, compile, and execute programs Provides facilities to help test programs and isolate errors Provides help facilities Object-Oriented Application Development Using VB .NET
48
Getting Started with VB .NET
To start VB .NET in Windows XP Professional: Click the Start button Point to All Programs Point to Microsoft Visual Studio .NET Click Microsoft Visual Studio .NET The Microsoft Development Environment (MDE) window opens Object-Oriented Application Development Using VB .NET
49
Getting Started with VB .NET
Object-Oriented Application Development Using VB .NET
50
Object-Oriented Application Development Using VB .NET
Exploring the MDE MDE includes a menu bar, toolbars, and windows The menu bar is used to perform tasks such as: Opening and closing files Opening and closing projects Compiling, executing, and debugging programs Accessing help facilities Object-Oriented Application Development Using VB .NET
51
Object-Oriented Application Development Using VB .NET
Exploring the MDE Many toolbars are available in MDE Toolbars can be revealed or hidden MDE includes a number of windows, such as: Document window Solution Explorer window Properties window Object-Oriented Application Development Using VB .NET
52
Object-Oriented Application Development Using VB .NET
Exploring the MDE Start Page appears as a tabbed page within a document window Tabs along the side of the screen identify hidden windows Object-Oriented Application Development Using VB .NET
53
Understanding the Start Page
Start Page contains a number of links to resources Clicking the Get Started link displays a list of recent projects To open a project on the list, click the project name Object-Oriented Application Development Using VB .NET
54
Understanding the Start Page
The Get Started link also displays two buttons, Open Project and New Project: Open Project button is clicked to work on a project not on the list of recent projects New Project button is clicked to create a new project Object-Oriented Application Development Using VB .NET
55
Understanding the Start Page
Object-Oriented Application Development Using VB .NET
56
Creating a Project Using VB .NET
To create a VB .NET project, identify: Type of project Template to use Project name and location To create a Visual Basic project, project type must be Visual Basic A template is a pattern for creating a specific type of application Object-Oriented Application Development Using VB .NET
57
Understanding the Way VB .NET Organizes Your Programs
Solution Explorer window shows hierarchical arrangement of items that make up the solution In VB .NET, programs are named with a .vb file extension By default, VB .NET names programs as Module1.vb, Module2.vb, and so on More descriptive names can be assigned by programmer Object-Oriented Application Development Using VB .NET
58
Understanding the Way VB .NET Organizes Your Programs
A project is a mechanism for grouping related files, for example: Program files Image files Other miscellaneous items A solution is a container for one or more projects Solution file appears at the top of the hierarchy in Solution Explorer window Object-Oriented Application Development Using VB .NET
59
Understanding the Way VB .NET Organizes Your Programs
If a solution contains more than one project, the startup project must be designated Startup project is the project that will be executed first Object-Oriented Application Development Using VB .NET
60
Object-Oriented Application Development Using VB .NET
Using the Text Editor Visual Studio .NET text editor provides: Standard text editing capabilities Color-coding feature Code indentation feature Code completion feature Object-Oriented Application Development Using VB .NET
61
Object-Oriented Application Development Using VB .NET
Renaming Module1.vb Descriptive names should be assigned to programs By default, VB .NET names programs as Module1.vb, Module2.vb, and so on File Name property in Properties window is used to rename programs Object-Oriented Application Development Using VB .NET
62
Setting 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 Object-Oriented Application Development Using VB .NET
63
Compiling 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 Object-Oriented Application Development Using VB .NET
64
Using 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 Object-Oriented Application Development Using VB .NET
65
Using 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 Object-Oriented Application Development Using VB .NET
66
Creating a Windows Application
In a Windows application, Windows Forms Designer can be used to create an input form In a new Windows application, Windows Forms Designer appears as a tabbed document labeled Form1.vb [Design] Object-Oriented Application Development Using VB .NET
67
Creating a Windows Application
Properties window shows properties of a form that is open Background of the form shows a grid to help align components Along the outer edges of the form are handles used to resize the form Object-Oriented Application Development Using VB .NET
68
Creating a Windows Application
Object-Oriented Application Development Using VB .NET
69
Customizing the Appearance of a Form
Size of the form can be changed using the handles along its outer edges Object-Oriented Application Development Using VB .NET
70
Customizing the Appearance of a Form
To change title of the form, use Text property in Properties window Object-Oriented Application Development Using VB .NET
71
Customizing the Appearance of a Form
To change background color of the form, use BackColor property in Properties window Object-Oriented Application Development Using VB .NET
72
Adding Components to a Form
Toolbox contains components which can be added to a form Object-Oriented Application Development Using VB .NET
73
Adding Components to a Form
To add a message to a form, use Label component Color of label text is changed using ForeColor property in Properties window Object-Oriented Application Development Using VB .NET
74
Adding Components to a Form
To change label font, use Font property in Properties window Object-Oriented Application Development Using VB .NET
75
Adding Components to a Form
To center label text within the area occupied by label, use TextAlign property in Properties window Object-Oriented Application Development Using VB .NET
76
Adding Components to a Form
To add a button to the form, double-click Button component of Toolbox A button’s appearance can be changed by using Properties window Text editor can be used to add code to make a button work Object-Oriented Application Development Using VB .NET
77
Adding Components to a Form
Object-Oriented Application Development Using VB .NET
78
Exploring the Debugging Tools
A debugger helps isolate errors that keep a program from running as intended A debugger can be used to set breakpoints A breakpoint is a flag that tells the debugger to temporarily suspend execution of program at a particular point Object-Oriented Application Development Using VB .NET
79
Getting Started with the Debugger
Debugger is used to identify errors in the program that occur while the program is running Debugger cannot find coding errors that prevent the program from being built successfully Object-Oriented Application Development Using VB .NET
80
Object-Oriented Application Development Using VB .NET
Setting Breakpoints To set a breakpoint: In code window, right-click statement Click Insert Breakpoint on shortcut menu Object-Oriented Application Development Using VB .NET
81
Exploring the Help Facility
In VB .NET development environment, programmer can: Search for help on a specific item Browse a table of contents Scroll through an alphabetized index of topics VB .NET also includes: Dynamic help Context-sensitive help Object-Oriented Application Development Using VB .NET
82
Object-Oriented Application Development Using VB .NET
Accessing Help Most help features can be accessed through options on Help menu Object-Oriented Application Development Using VB .NET
83
Object-Oriented Application Development Using VB .NET
Accessing Help On Help menu: Contents option displays a list of help topics in a format resembling a table of contents Index option displays a list of help topics in alphabetical order Search option allows programmer to search the database of help pages Dynamic Help option dynamically identifies help topics in response to actions taken by programmer Object-Oriented Application Development Using VB .NET
84
Exploring Context-Sensitive Help
Context-sensitive help can be invoked by pressing the F1 key F1 key can be pressed to obtain help on virtually any keyword, component, window, or other element of VB .NET Object-Oriented Application Development Using VB .NET
85
Object-Oriented Application Development Using VB .NET
Summary Visual Studio .NET is an integrated development environment (IDE) An IDE is a set of software tools that helps you code, debug, and test a system as you develop it Visual Basic .NET is a programming language supported by Visual Studio .NET IDE VB .NET text editor supports color-coding, indentation, and code completion features Windows Forms Designer is a visual development tool that generates code from icons Object-Oriented Application Development Using VB .NET
86
Object-Oriented Application Development Using VB .NET
Summary VB .NET uses a hierarchical arrangement of solutions and projects A debugger is a tool that helps identify problems that prevent a program from running as intended A breakpoint is a flag that instructs debugger to temporarily suspend execution of a program Help facilities of VB .NET include Contents window, Index window, Search window, Dynamic Help, and context-sensitive help Object-Oriented Application Development Using VB .NET
87
VB .NET Programming Fundamentals
Chapter 3 VB .NET Programming Fundamentals Object-Oriented Application Development Using VB .NET
88
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Learn about the VB .NET programming language Write a VB .NET module definition Use VB .NET variables and data types Compute with VB .NET Write decision-making statements Write loops Declare and access arrays Object-Oriented Application Development Using VB .NET
89
Object-Oriented Application Development Using VB .NET
Introducing VB .NET VB .NET: Has achieved popularity and widespread acceptance Is a powerful, full-featured, object-oriented development language Is easy to learn and use Supports development of applications for networked environments Object-Oriented Application Development Using VB .NET
90
Object-Oriented Application Development Using VB .NET
Introducing VB .NET By adopting the OO model, VB .NET encourages good software design Good software design can reduce: Debugging chores Maintenance chores Object-Oriented Application Development Using VB .NET
91
Writing 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 Object-Oriented Application Development Using VB .NET
92
Writing a VB .NET Module Definition
The VB .NET statements consist of keywords and identifiers Keywords have special meanings to VB .NET VB .NET identifiers are the names assigned by the programmer to modules, procedures, and variables, etc. 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 Object-Oriented Application Development Using VB .NET
93
Writing a VB .NET Module Definition
VB .NET code is not case sensitive VB .NET compiler does not require indentation of code, but good programming practice encourages indentation Comment lines: Add explanations to code Are ignored by compiler Begin with a single quote (') Object-Oriented Application Development Using VB .NET
94
Writing a VB .NET Module Definition
Procedures begin with a procedure header, which identifies the procedure and describes some of its characteristics VB .NET has two types of procedures: Function and Sub A Function procedure can return a value A Sub procedure cannot return a value Object-Oriented Application Development Using VB .NET
95
Writing a VB .NET Module Definition
Many statements invoke a method to do some work Information sent to a method is called an argument A literal is a value defined within a statement Object-Oriented Application Development Using VB .NET
96
Using 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 Object-Oriented Application Development Using VB .NET
97
Declaring and Initializing Variables
Before 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 Object-Oriented Application Development Using VB .NET
98
Declaring 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 variable Dim i As Integer Object-Oriented Application Development Using VB .NET
99
VB.NET Primitive Data Types
Range of Value Size Numeric with no decimal Byte 0 to 255 8 bits Short to 16 bits Integer 32 bits Long 64 bits Numeric with decimal Single Double Decimal 128 bits other Boolean True or False Char Any Unicode char Object-Oriented Application Development Using VB .NET
100
Declaring 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 Object-Oriented Application Development Using VB .NET
101
Declaring and Initializing Variables
The code to both declare and initialize a variable can be written in one statement: ' declare a variable Dim i As Integer = 1 Several variables of the same data type can be declared in one statement: Dim x, y, z As Integer Object-Oriented Application Development Using VB .NET
102
Object-Oriented Application Development Using VB .NET
Changing Data Types Option Strict helps prevent unintentional loss of precision when assigning values to variables If Option Strict is set to On, whenever an assignment statement that may result in a loss of precision is written, VB .NET compiler displays an error message Object-Oriented Application Development Using VB .NET
103
Object-Oriented Application Development Using VB .NET
Changing Data Types With Option Explicit On, the programmer must define a variable before using it in a statement Option Explicit is generally set to On Object-Oriented Application Development Using VB .NET
104
Object-Oriented Application Development Using VB .NET
Using 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 Object-Oriented Application Development Using VB .NET
105
Using 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; instead, it refers to an instance of a class that contains the data Object-Oriented Application Development Using VB .NET
106
Using Reference Variables
Object-Oriented Application Development Using VB .NET
107
Object-Oriented Application Development Using VB .NET
Computing with VB .NET VB .NET uses: Arithmetic operators (+, –, *, /) for addition, subtraction, multiplication, and division Parentheses to group parts of an expression and establish precedence Remainder operator (Mod) produces a remainder resulting from the division of two integers Integer division operator (\) to produce an integer result Caret (^) for exponentiation Object-Oriented Application Development Using VB .NET
108
Object-Oriented Application Development Using VB .NET
Computing 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 Object-Oriented Application Development Using VB .NET
109
Writing Decision-Making Statements
Decision-making 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 Object-Oriented Application Development Using VB .NET
110
Writing 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 Object-Oriented Application Development Using VB .NET
111
Object-Oriented Application Development Using VB .NET
Writing If Statements VB .NET If statement interrogates a logical expression that evaluates to true or false An expression often compares two values using logical operators Object-Oriented Application Development Using VB .NET
112
Object-Oriented Application Development Using VB .NET
Writing If Statements Object-Oriented Application Development Using VB .NET
113
Object-Oriented Application Development Using VB .NET
Writing 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 Object-Oriented Application Development Using VB .NET
114
Object-Oriented Application Development Using VB .NET
Writing If Statements Object-Oriented Application Development Using VB .NET
115
Object-Oriented Application Development Using VB .NET
Writing If Statements If-Else Evaluates an expression Executes one or more statements if expression is true Executes a second statement or set of statements if expression is false Object-Oriented Application Development Using VB .NET
116
Object-Oriented Application Development Using VB .NET
Writing If Statements Object-Oriented Application Development Using VB .NET
117
Writing Select Case Statements
Acts like a multiple-way If statement Transfers control to one of several statements, depending on the value of an expression Object-Oriented Application Development Using VB .NET
118
Object-Oriented Application Development Using VB .NET
Writing Loops Loops: repeated execution of one or more statements until a terminating condition occurs Three types of loops: Do While Do Until For Next Object-Oriented Application Development Using VB .NET
119
Object-Oriented Application Development Using VB .NET
Writing Do While Loops Use a Do While to display the numbers 1- 3: ' do while loop ' declare and initialize loop counter variable Dim i As Integer = 1 Do While i <= 3 Console.WriteLine("do while loop: i = " & i) i += 1 Loop Object-Oriented Application Development Using VB .NET
120
Object-Oriented Application Development Using VB .NET
Writing Do While Loops Do While loop continues executing the statement as long as the expression evaluates to true An infinite loop: loop that does not terminate without outside intervention While loop A variation of the Do While loop Functions like the Do While loop Object-Oriented Application Development Using VB .NET
121
Object-Oriented Application Development Using VB .NET
Writing Do Until Loops A Do Until loop: ' do until loop i = 1 ' re-initialize loop counter variable Do Until i > 3 Console.WriteLine("do until loop: i = " & i) i += 1 Loop Object-Oriented Application Development Using VB .NET
122
Object-Oriented Application Development Using VB .NET
Writing Do Until Loops Difference between a Do While and Do Until loop: Do While loop executes while the expression is true Do Until loop executes until the expression is false Object-Oriented Application Development Using VB .NET
123
Writing 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 Object-Oriented Application Development Using VB .NET
124
Writing Post-Test Loops
Object-Oriented Application Development Using VB .NET
125
Writing Post-Test Loops
Do While and Do Until loops can be written as either pre-test or post-test loops For Next and While loops are always pre-test Object-Oriented Application Development Using VB .NET
126
Object-Oriented Application Development Using VB .NET
Writing For Next Loops VB .NET For Next loop: Includes loop counter initialization and incrementing code as a part of the For statement Uses pre-test logic – it evaluates the terminating expression at the beginning of the loop Example: ' for next loop For i = 1 To 3 Step 1 Console.WriteLine("for next loop: i = " & i) Next Object-Oriented Application Development Using VB .NET
127
Object-Oriented Application Development Using VB .NET
Writing Nested Loops Nested loop: A loop within a loop Can be constructed using any combination of Do While, Do Until, or For Next loops Object-Oriented Application Development Using VB .NET
128
Declaring 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 Object-Oriented Application Development Using VB .NET
129
Declaring 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 Object-Oriented Application Development Using VB .NET
130
Using One-Dimensional Arrays
Declare a 5-element array with of integers: ' declare an integer array with 5 elements Dim testScores(4) As Integer Individual array elements are accessed by writing the array reference variable, followed by the index value of the element enclosed in parentheses Object-Oriented Application Development Using VB .NET
131
Using One-Dimensional Arrays
Code to initialize the array elements: testScores(0) = 75 testScores(1) = 80 testScores(2) = 70 testScores(3) = 85 testScores(4) = 90 An array can be declared and populated using a single statement: Dim testScores() As Integer = {75, 80, 70, 85, 90} Object-Oriented Application Development Using VB .NET
132
Using One-Dimensional Arrays
Object-Oriented Application Development Using VB .NET
133
Using 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 Object-Oriented Application Development Using VB .NET
134
Using Multidimensional Arrays
Code to populate the array: ' populate the elements in column 1 testScoreTable(0, 0) = 75 testScoreTable(1, 0) = 80 testScoreTable(2, 0) = 70 testScoreTable(3, 0) = 85 testScoreTable(4, 0) = 90 ' populate the elements in column 2 testScoreTable(0, 1) = 80 testScoreTable(1, 1) = 90 testScoreTable(2, 1) = 60 testScoreTable(3, 1) = 95 testScoreTable(4, 1) = 100 Object-Oriented Application Development Using VB .NET
135
Using Multidimensional Arrays
Object-Oriented Application Development Using VB .NET
136
Object-Oriented Application Development Using VB .NET
Summary An identifier is the name of a class, method, or variable All variables have a data type, name, and value VB .NET has nine primitive data types VB .NET has two kinds of variables: primitive variables and reference variables Math class has methods to accomplish exponentiation, rounding, etc. VB .NET provides two types of decision-making statements: If statement and Select Case statement Object-Oriented Application Development Using VB .NET
137
Object-Oriented Application Development Using VB .NET
Summary You write VB .NET loops using one of three keywords: Do While, Do Until, or For Next There are two kinds of loops: pre-test loop and post-test loop A nested loop is a loop within a loop A one-dimensional array consists of elements arranged in a single row A two-dimensional array has both rows and columns Object-Oriented Application Development Using VB .NET
138
VB .NET Programming with Supplied Classes
Chapter 4 VB .NET Programming with Supplied Classes Object-Oriented Application Development Using VB .NET
139
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Use the namespaces and classes supplied with VB .NET Use the String class Create a String array Use the ArrayList class Work with dates Format numeric output Use the MessageBox class Display a Form Object-Oriented Application Development Using VB .NET
140
Using the Namespaces and Classes Supplied with VB .NET
Two important pieces of .NET framework: Common Language Runtime (CLR) .NET class library CLR supports common services used by Visual Studio .NET languages. .NET class library: Huge number of predefined classes are organized into namespaces. Object-Oriented Application Development Using VB .NET
141
Using the Namespaces and Classes Supplied with VB .NET
Namespace : It is a container to group related classes. The Namespace is a method for organizing the .NET class library into tree form. It looks like the Folder concept that is used for organizing the files existed on disks in tree form. Keyword Imports: gives compiler access to classes contained in specific namespaces Object-Oriented Application Development Using VB .NET
142
Object-Oriented Application Development Using VB .NET
Using the String Class String: collection of characters VB .NET stores string data in instances of String class String class is a member of System namespace Code to declare a string: Dim s1 As String = "Hello Again" The following steps will be done to execute the above statement Create variable s1 with data type String. Create String instance. Populate the instance with "Hello Again“ value. Assigns the location of this instance to variable s1. Object-Oriented Application Development Using VB .NET
143
Object-Oriented Application Development Using VB .NET
Using the String Class Object-Oriented Application Development Using VB .NET
144
Object-Oriented Application Development Using VB .NET
Using the String Class String values in VB .NET are immutable – they cannot be changed by the methods appeared as changing methods. Methods that appear to change a string value, such as Insert, Replace, and ToUpper actually create and return a new String instance Those methods create and return a new String instance. You can change its value directly like primitive variable. Example: Dim s1 As String = "Hello" S1 = "Hello Again" Index: Each character in a String instance has an index Index values in VB .NET begin with zero Object-Oriented Application Development Using VB .NET
145
Object-Oriented Application Development Using VB .NET
Using String Methods Copy method returns a second String that is a copy of the String sent as an argument Dim s1 As String = "Hello Again" ' create a copy of s1 Dim s2 As String = String.Copy(s1) Console.WriteLine("s2, a copy of s1, contains " & s2) Chars method returns the character at a specified index Note: Index will start from Zero value. Console.WriteLine("char at index 6 of s1 is " & s1.Chars(6)) Object-Oriented Application Development Using VB .NET
146
Object-Oriented Application Development Using VB .NET
Using String Methods There are two options to compare two string values: Equals method Console.WriteLine("s1.Equals(s2) returns " & s1.Equals(s2)) Equal sign (=) , Compiler will invoke Equals method on behalf of you. If s1 = s2 Then Console.WriteLine("s1 = s2") Object-Oriented Application Development Using VB .NET
147
Object-Oriented Application Development Using VB .NET
Using String Methods SubString method: Extracts one or more characters from a String instance, and Returns a new String instance containing extracted characters. Console.WriteLine("s1.Substring(0, 5) returns " & _ s1.Substring(0, 5)) Object-Oriented Application Development Using VB .NET
148
Object-Oriented Application Development Using VB .NET
Using String Methods Replace method replaces one or more characters in a string with one or more other characters Console.WriteLine("s1.Replace(Hello, Hi) returns " & _ s1.Replace("Hello", "Hi")) Console.WriteLine("After Replace s1 contains " & s1) Object-Oriented Application Development Using VB .NET
149
Object-Oriented Application Development Using VB .NET
Using String Methods Insert method inserts one or more characters into an existing string beginning at a specified index Console.WriteLine("s1.Insert(6, There ) returns " & _ s1.Insert(6, "There ")) Object-Oriented Application Development Using VB .NET
150
Object-Oriented Application Development Using VB .NET
Using String Methods StartsWith method Compares the string argument with beginning characters of the String instance Returns True or False depending on whether there is a match Console.WriteLine("s1.StartsWith(Hi) returns " & _ s1.StartsWith("Hi")) Object-Oriented Application Development Using VB .NET
151
Object-Oriented Application Development Using VB .NET
Using String Methods EndsWith method compares the ending characters with the argument Console.WriteLine("s1.EndsWith(Again) returns " & _ s1.EndsWith("Again")) Use ToUpper method to change the case of a string value to uppercase Use ToLower method to change the case of a string value to lowercase Object-Oriented Application Development Using VB .NET
152
Object-Oriented Application Development Using VB .NET
Using String Methods IndexOf method Searches a String instance for a specific value Returns index of the beginning of the value Returns –1 if no matching value was found Console.WriteLine("s1.indexof(Again) returns " & _ s1.IndexOf("Again")) Object-Oriented Application Development Using VB .NET
153
Object-Oriented Application Development Using VB .NET
Using String Methods Use ToString method to convert numeric values to a string ' convert an integer to String Dim i As Integer = 5 Console.WriteLine("value of Convert.ToString(i) is " & _ Convert.ToString(i)) Use methods in Convert class to convert String values containing numeric data to primitive data types & vice versa. Object-Oriented Application Development Using VB .NET
154
Creating a String Array
Code to create a String array: ' declare a String array with 4 elements Dim stringArray(3) As String Elements of stringArray are reference variables of data type String Object-Oriented Application Development Using VB .NET
155
Creating a String Array
Code to create four String instances and populate the array elements stringArray(0) = "Hello" stringArray(1) = "World" stringArray(2) = "Wide" stringArray(3) = "Web" A specific element can be accessed using the index of that element String methods can be invoked for String instances referenced by array elements . For example: - console.writeline(“Length of first element: ” & stringArray(0).length) Object-Oriented Application Development Using VB .NET
156
Creating a String Array
Object-Oriented Application Development Using VB .NET
157
Using the ArrayList Class
Major limitation of arrays: fixed size ArrayList class Member of System.Collections namespace Creates dynamically resizable array – the number of elements can change during runtime Code to create an instance of ArrayList class: ' create an ArrayList instance Dim dynArr As ArrayList = New ArrayList( ) ‘ OR Dim dynArr As New ArrayList( ) Object-Oriented Application Development Using VB .NET
158
Using the ArrayList Class
Code to create four instances of String class: ' create String instances Dim s1 As String = New String("Hello") Dim s2 As String = New String("World") Dim s3 As String = New String("Wide") Dim s4 As String = New String("Web") Add method is used to populate the elements When a fourth element is added, the number of elements increases automatically dynArr.Add(s1) dynArr.Add(s2) dynArr.Add(s3) dynArr.Add(s4) Object-Oriented Application Development Using VB .NET
159
Using the ArrayList Class
The following Methods/Properties are defined in the ArrayList Class : Contains(O) - > return True if O is in ArrayList object, and False if O is not in ArrayList object. Capacity -> Gets/Sets No. of Elements. Count -> return populated elements. Remove(O) -> removes first occurrence of O object. Reverse( ) -> reverses the element sequence. IndexOf( O ) -> return the index of first occurrence of O, and –1 otherwise. Item( i ) -> sets/gets the object at index i . This property can be used to loop through the array elements. Object-Oriented Application Development Using VB .NET
160
Object-Oriented Application Development Using VB .NET
Working with Dates System namespace contains DateTime class and TimeSpan class Instance of DateTime class contains a date & time value Instance of TimeSpan class contains the difference between two dates Object-Oriented Application Development Using VB .NET
161
Object-Oriented Application Development Using VB .NET
Working with Dates DateTime properties Today property gets system date and returns a DateTime instance Now property captures the current time DateTime methods to perform arithmetic on a date value AddMonths adds a value to the month AddDays adds a value to the day AddYears adds a value to the year Object-Oriented Application Development Using VB .NET
162
Object-Oriented Application Development Using VB .NET
Working with Dates To format a date: Invoke its ToString method Pass arguments that describe the desired format For example: Code to return a date in the format “February 15, 2003”: DateTime.today.ToString("MMMM dd,yyyy") Note: Look page 147 in book for formatting date Object-Oriented Application Development Using VB .NET
163
Object-Oriented Application Development Using VB .NET
Working with Dates Subtract method Computes the number of days between two DateTime instances Returns an instance of the TimeSpan class Compare method Compares two DateTime instances Returns –1 -> first DateTime instance is less than the second. 0 -> they are equal. +1 -> first DateTime instance greater than the second. Object-Oriented Application Development Using VB .NET
164
Formatting Numerical Output
Formatting means inserting commas, decimal places, dollar signs, percent symbols, parentheses, hyphens, etc. Each primitive data type is represented by a structure, which has methods When a primitive variable is declared, certain methods associated with that variable can be invoked For example: ToString method Object-Oriented Application Development Using VB .NET
165
Formatting Numerical Output
ToString method is used to format numeric data Format mask A series of characters that describes the format to be used. Passed to ToString method to carry out formatting. For example: S = i.ToString("$#,###.00") Console.WriteLine("Integer 1234 with $#,##0.00 format is " & s) Output: $1,234.00 Object-Oriented Application Development Using VB .NET
166
Formatting Numerical Output
Using ToString method, a number can be formatted As currency -> argument “C” can be used With or without commas -> argument “N”, and “F” can be used respectively . As a percentage -> argument “P” can be used As a telephone number As a Social Security number Dim sn as double = S = sn.Tostring(“###-##-###”) Object-Oriented Application Development Using VB .NET
167
Using the MessageBox Class
A message box can be used to display a message and to get a response. MessageBox class Member of System.Windows.Forms namespace Has a single method named Show Show method Creates an instance of MessageBox class Makes a message box appear Object-Oriented Application Development Using VB .NET
168
Using the MessageBox Class
Show method can receive up to four arguments First argument : Message to be displayed Object-Oriented Application Development Using VB .NET
169
Using the MessageBox Class
Show method can receive up to four arguments Second argument : Caption to be displayed Object-Oriented Application Development Using VB .NET
170
Using the MessageBox Class
Show method can receive up to four arguments Third argument : Specifies the buttons to be displayed Object-Oriented Application Development Using VB .NET
171
Using the MessageBox Class
Show method can receive up to four arguments Fourth argument : Specifies the type of icon displayed Object-Oriented Application Development Using VB .NET
172
Using the MessageBox Class
Return value obtained from Show method Indicates which button was clicked by user Is of data type DialogResult Can be compared to specific values using an If statement Example: - Object-Oriented Application Development Using VB .NET
173
Object-Oriented Application Development Using VB .NET
Example Dim res As DialogResult res = MessageBox.Show("Hello", "Msg", _ MessageBoxButtons.YesNoCancel, _ MessageBoxIcon.Question) If res = DialogResult.Yes Then MessageBox.Show("You have presses Yes") ElseIf res = DialogResult.No Then MessageBox.Show("You have presses No") Else MessageBox.Show("You have presses Cancel") End If Object-Oriented Application Development Using VB .NET
174
Object-Oriented Application Development Using VB .NET
Displaying a Form Form A class in System.Windows.Forms namespace GuiModule.vb module contains instructions to Instantiate GuiForm.vb Form Make it visible and invisible GuiForm.vb A subclass of Form Inherits Form attributes and methods Object-Oriented Application Development Using VB .NET
175
Object-Oriented Application Development Using VB .NET
Example Dim myForm As GuiForm myForm = New GuiForm() myForm.Text = "My GUI Form Demo" myForm.BackColor = System.Drawing.Color.Brown ' use MessageBox to determine what to do Dim result As DialogResult Do Until result = DialogResult.Cancel result = MessageBox.Show("Press Yes to Show, No to Hide, Cancel to stop", "Form Demo", MessageBoxButtons.YesNoCancel) If result = DialogResult.Yes Then myForm.Visible = True If result = DialogResult.No Then myForm.Visible = False Loop myForm.Dispose() Object-Oriented Application Development Using VB .NET
176
Object-Oriented Analysis and Design
Chapter 5 Object-Oriented Analysis and Design Object-Oriented Application Development Using VB .NET
177
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Explore OOA and OOD Understand the Unified Modeling Language (UML) Use three-tier design in OO development Learn about the Bradshaw Marina case study Object-Oriented Application Development Using VB .NET
178
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD System analysis: Study Understand Define the system requirements System design: show how various system components will be implemented using specific technology Object-Oriented Application Development Using VB .NET
179
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD System requirements Define what the system needs to accomplish for users in business terms Usually described using Diagrams Models Object-Oriented Application Development Using VB .NET
180
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD A model depicts some aspect of the required system Logical models: created during system analysis Physical models: created during system design Model-driven development: creating logical and physical models during analysis and design Object-Oriented Application Development Using VB .NET
181
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD OO development models Define classes of objects Depict object interactions Are based on UML Include Use case diagrams Class diagrams Sequence diagrams Object-Oriented Application Development Using VB .NET
182
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD OO development works well with an iterative approach to development Iterative development Analysis, design, and programming are performed in parallel, with the process repeated several times until the project is done Contrasts with the waterfall method An earlier approach All of analysis was completed before design could start, and all of design was completed before programming could start Object-Oriented Application Development Using VB .NET
183
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD Object-Oriented Application Development Using VB .NET
184
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD OO development also uses incremental development Some of the system is completed and put into operation before the entire system is finished Object-Oriented Application Development Using VB .NET
185
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD Spiral model An increasingly popular approach to development Emphasizes the iterative nature of development Project appears as a spiral starting in the middle and working its way out Development team completes analysis, design, prototyping, and evaluation tasks for each iteration, starting in the middle of spiral Object-Oriented Application Development Using VB .NET
186
Object-Oriented Application Development Using VB .NET
Exploring OOA and OOD Object-Oriented Application Development Using VB .NET
187
Understanding the Unified Modeling Language
Object-oriented development requires a collection of models that depict system requirements and designs UML defines a standard set of constructs and diagrams to model OO systems Object-Oriented Application Development Using VB .NET
188
Creating and Interpreting the Use Case Diagram
First step in system modeling: define the main system functions A use case diagram shows two key concepts: Use case: a system function Actor: person or entity using the system Object-Oriented Application Development Using VB .NET
189
Creating and Interpreting the Use Case Diagram
Object-Oriented Application Development Using VB .NET
190
Creating and Interpreting the Use Case Diagram
One approach to identifying use cases is to identify events the system must respond to Three types of events can affect a system: External events: occur outside the system and require the system to respond Temporal events: occur at a specific point in time, such as at the end of each day or at the end of the month State event: occur when the properties of an object change. Require system processing Object-Oriented Application Development Using VB .NET
191
Creating and Interpreting the Use Case Diagram
Each use case can be documented as a series of steps users follow when they interact with the system Scenarios: variations in the main steps As the development team identifies use cases, it creates use case diagrams Object-Oriented Application Development Using VB .NET
192
Creating and Interpreting the Use Case Diagram
An activity diagram An additional diagram defined by UML that can be used to document use cases Sometimes created for each scenario for a use case Object-Oriented Application Development Using VB .NET
193
Creating and Interpreting the Class Diagram
Shows the classes involved in the system Is a rectangle with three sections Top section contains name of the class Middle section contains attributes of the class Bottom section contains methods of the class Object-Oriented Application Development Using VB .NET
194
Creating and Interpreting the Class Diagram
Object-Oriented Application Development Using VB .NET
195
Creating and Interpreting the Class Diagram
Association relationship between two classes is shown with a line connecting the two classes Number of associations between classes is written on each end of the line UML refers to the number of associations as multiplicity Object-Oriented Application Development Using VB .NET
196
Creating and Interpreting the Class Diagram
Shows generalization/specialization hierarchies (inheritance) Abstract classes shown in italics Objects cannot be created for an abstract class Only serves to allow subclasses to inherit from it Object-Oriented Application Development Using VB .NET
197
Creating and Interpreting a Sequence Diagram
Object-Oriented Application Development Using VB .NET
198
Creating and Interpreting a Sequence Diagram
Shows interactions between objects in a system, usually for one use case or scenario Often called a dynamic model Class diagram Does not highlight object interactions Often called a static model Object-Oriented Application Development Using VB .NET
199
Creating and Interpreting a Sequence Diagram
In a sequence diagram Actor can be shown as a stick figure or a rectangle Objects are shown as rectangles Lifelines Represent a sequence of time Shown as either a dashed line or a narrow box Horizontal arrows represent messages sent or received in sequence Data returned in response to a message is shown as a dashed line Object-Oriented Application Development Using VB .NET
200
Creating and Interpreting a Sequence Diagram
Object-Oriented Application Development Using VB .NET
201
Creating and Interpreting a Sequence Diagram
In a sequence diagram Object names are always underlined and begin with a lowercase letter Class names are always capitalized Objects can be named by Using generic object names to clarify the class Including the name of the class after the name of the object, separated by a colon Message names are written above the message line Object-Oriented Application Development Using VB .NET
202
Using Three-Tier Design in OO Development
Three-tier design requires that OO system developers separate three categories of classes when designing and building a system Three tiers Graphical user interface (GUI) classes Problem domain classes Data access classes Object-Oriented Application Development Using VB .NET
203
Using Three-Tier Design in OO Development
Separating GUI classes, problem domain classes, and data access classes leads to loosely coupled system components With loosely coupled components A component can be modified with minimal effects on other components Makes it easier to maintain and enhance the system Components are easier to reuse Object-Oriented Application Development Using VB .NET
204
Using Three-Tier Design in OO Development
Provides a framework for defining OOA and OOD OOA involves identifying and modeling the problem domain classes In OOD, decisions about the user interface and about database management are made Works well with Iterative development Incremental development The book follows the three-tier design approach Object-Oriented Application Development Using VB .NET
205
Introducing the Bradshaw Marina Case Study
Bradshaw Marina case study demonstrates OO development principles and practices When a business determines it needs a computer system, it works with a team of developers to design and develop the system Object-Oriented Application Development Using VB .NET
206
Introducing the Bradshaw Marina Case Study
Tasks of development team Analyze business and identify system functions Begin object-oriented analysis to identify the required use cases and scenarios, creating use case diagrams Identify required problem domain classes and create class diagram Develop sequence diagrams to model object interactions Object-Oriented Application Development Using VB .NET
207
Exploring the Background of Bradshaw Marina
A privately owned corporation that rents boat slips and provides boat services on Clinton Lake Wants an automated system to track customers, slips they lease, and boats in the slips Object-Oriented Application Development Using VB .NET
208
Exploring the Background of Bradshaw Marina
System Initially: system will maintain basic information for customers, slips, and boats, and perform day-to-day business tasks Later: Bradshaw wants to enhance the system Add boat service records Add billing features Object-Oriented Application Development Using VB .NET
209
Identifying Bradshaw Use Cases and Scenarios
First step in OOA process: identify use cases that fall within system scope Since main events of interest involve customers, boats, and slips, use cases also focus on customers, boats, and slips Bradshaw Marina use case diagram indicates the use cases Several scenarios could be associated with each use case Object-Oriented Application Development Using VB .NET
210
Identifying Bradshaw Use Cases and Scenarios
Object-Oriented Application Development Using VB .NET
211
Identifying Bradshaw Problem Domain Classes
To explore problem domain classes, the development team would Meet with Bradshaw Marina to ask about things that are involved in the work of the marina For example – customers, boats, leases, slips, and docks Begin an initial class diagram that includes these potential classes Object-Oriented Application Development Using VB .NET
212
Identifying Bradshaw Problem Domain Classes
Development team would further develop the class diagram by Showing generalization/specialization hierarchies Adding specific information about each class Identifying and modeling the association relationship among classes Object-Oriented Application Development Using VB .NET
213
Creating a Bradshaw Sequence Diagram
Methods can be added to the class diagram by exploring scenarios and documenting them with sequence diagrams A sequence diagram should be created for each scenario of each use case As you move from OOA to OOD, you will expand the diagram to show GUI objects the actor interacts with Data access classes that handle interaction with database Object-Oriented Application Development Using VB .NET
214
Object-Oriented Application Development Using VB .NET
Summary System analysis: study, understand, and define requirements for the system System requirements define what a system needs to accomplish for users in business terms Model-driven development: creating logical and physical models during analysis and design Iterative development: analysis, design, and programming are performed in parallel, with the process repeated several times until the project is done Object-Oriented Application Development Using VB .NET
215
Object-Oriented Application Development Using VB .NET
Summary Incremental development: part of the system is put to use before the rest is finished Use case diagram shows system functions, called use cases Class diagram shows classes of objects that interact in the system Sequence diagram shows messages that the actor sends to objects and that objects send to each other Three-tier design divides classes into GUI classes, problem domain classes, and data access classes Object-Oriented Application Development Using VB .NET
216
Writing a Problem Domain Class Definition
Chapter 6 Writing a Problem Domain Class Definition Object-Oriented Application Development Using VB .NET
217
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Learn VB .NET naming conventions Develop a problem domain (PD) class definition Define attributes Write methods and properties Test a PD class Object-Oriented Application Development Using VB .NET
218
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Create an instance Write a constructor method Write a TellAboutSelf method Write a Tester class as a Form Object-Oriented Application Development Using VB .NET
219
VB .NET Naming Conventions
Class names Start with a capital letter Examples: Customer, Boat Attribute names Begin with a lowercase character Subsequent words are capitalized Examples: address, phoneNo Method names Begin with an uppercase character Examples: GetPhoneNo, SetAddress, ComputeLease Object-Oriented Application Development Using VB .NET
220
Developing a PD Class Definition
Bradshaw Marina system PD classes include Customer Boat Slip Dock Class definition Code that represents a class Contains attributes and methods of the object Object-Oriented Application Development Using VB .NET
221
Developing a PD Class Definition
Customer class Represents marina’s customers Has attributes for customer’s Name Address Telephone number Object-Oriented Application Development Using VB .NET
222
Developing a PD Class Definition
Object-Oriented Application Development Using VB .NET
223
Class Definition Structure
Structure of a class definition Class header Attribute definitions Method code Line of code that identifies the class and some of its characteristics Object-Oriented Application Development Using VB .NET
224
Class Definition Structure
Class header for the Customer definition: Public Class Customer Keyword Public indicates that the class has public accessibility Keyword Class indicates that this line of code is a class header Customer establishes the class name Object-Oriented Application Development Using VB .NET
225
Object-Oriented Application Development Using VB .NET
Defining Attributes Attributes: defined by declaring variables for each attribute An attribute definition Written in the same way as a variable is declared, except: Keyword Private is used instead of Dim Customer attributes are defined as follows: 'attributes Private name As String Private address As String Private phoneNo As String Object-Oriented Application Development Using VB .NET
226
Object-Oriented Application Development Using VB .NET
Defining Attributes When defining attributes, a variable’s accessibility can be: Public: allows any class to access the variable directly Private: prohibits direct access; variable is accessible only within the class where it is defined Protected: allows subclasses to have direct access Friend: permits classes within the same assembly to have access Assembly: a collection of one or more projects deployed as an application Accessor methods can be invoked by other classes to access attribute values Object-Oriented Application Development Using VB .NET
227
Writing Methods and Properties
In OO systems, objects interact by one object sending a message to another object to invoke a method Client object: object sending the message Sends a message invoking a server method Can send values in the form of arguments Server object: object receiving the message Performs the requested task May return a value to the client Object-Oriented Application Development Using VB .NET
228
Writing Methods and Properties
Object-Oriented Application Development Using VB .NET
229
Writing Methods and Properties
Methods are written using procedures VB .NET has two types of procedures: Sub procedures and Function procedures A Sub procedure does not return a value A Function procedure returns a value A Sub procedure definition A procedure header followed by one or more statements accessibility Sub procedurename(parameter list) method statements End Sub Object-Oriented Application Development Using VB .NET
230
Writing Methods and Properties
A Function procedure definition A procedure header followed by one or more statements accessibility Function procedurename (parameter list) As datatype method statements End Function Object-Oriented Application Development Using VB .NET
231
Object-Oriented Application Development Using VB .NET
Defining Attributes Accessor methods Often called standard methods Typically not shown on class diagrams Custom methods Perform other functions Shown on class diagrams Object-Oriented Application Development Using VB .NET
232
Object-Oriented Application Development Using VB .NET
Defining Attributes Two types of accessor methods Get accessor methods or getters Retrieve, or get, attribute values Named with the prefix “Get” followed by the attribute name Set accessor methods or setters Change, or set, attribute values Named with the prefix “Set” followed by the attribute name Object-Oriented Application Development Using VB .NET
233
Object-Oriented Application Development Using VB .NET
Defining Attributes A property Can be used to set and get attribute values Similar to a method, but appears as an attribute to a client Begins with a header indicating a property definition Ends with End Property Object-Oriented Application Development Using VB .NET
234
Object-Oriented Application Development Using VB .NET
Testing a PD Class A tester class simulates the way a client might send messages For example: TesterOne class can invoke methods in the Customer class definition TesterOne is the client and Customer is the server TesterOne class Startup object for the project Main method begins execution when it is loaded Object-Oriented Application Development Using VB .NET
235
Object-Oriented Application Development Using VB .NET
Creating an Instance In TesterOne An instance of the Customer class is created A variable with data type Customer references this instance Creating an instance of a class: Dim firstCustomer As Customer = New Customer() ' create instance The variable firstCustomer points to the newly created Customer instance Object-Oriented Application Development Using VB .NET
236
Object-Oriented Application Development Using VB .NET
Creating an Instance Object-Oriented Application Development Using VB .NET
237
Object-Oriented Application Development Using VB .NET
Creating an Instance Attributes of the Customer instance initially have no values Instance attributes can be populated by Setter methods Properties Example of using properties CustomerName property can be used to populate the name attribute ' use property to populate name firstCustomer.CustomerName = "Eleanor" Object-Oriented Application Development Using VB .NET
238
Object-Oriented Application Development Using VB .NET
Creating an Instance Example of using setter methods ' invoke set accessors to populate attributes firstCustomer.SetName("Eleanor") firstCustomer.SetAddress("Atlanta") firstCustomer.SetPhoneNo(" ") Object-Oriented Application Development Using VB .NET
239
Object-Oriented Application Development Using VB .NET
Creating an Instance Object-Oriented Application Development Using VB .NET
240
Object-Oriented Application Development Using VB .NET
Creating an Instance Code to retrieve attribute values and display them: ' define variables to contain attribute values retrieved Dim customerName, customerAddress, customerPhoneNo As String customerName = firstCustomer.GetName() customerAddress = firstCustomer.GetAddress() customerPhoneNo = firstCustomer.GetPhoneNo() ' display the retrieved attribute values Console.WriteLine("The name is " + customerName) Console.WriteLine("The address is " + customerAddress) Console.WriteLine("The phone is " + customerPhoneNo) Object-Oriented Application Development Using VB .NET
241
Creating Multiple Instances
A tester class can create more than one instance of a class For example: TesterTwo will create three instances using the Customer class definition To create three instances, three reference variables are needed: Dim firstCustomer, secondCustomer, thirdCustomer As Customer Object-Oriented Application Development Using VB .NET
242
Creating Multiple Instances
Code to create three instances of the Customer class: firstCustomer = New Customer() secondCustomer = New Customer() thirdCustomer = New Customer() Object-Oriented Application Development Using VB .NET
243
Creating Multiple Instances
Code to invoke setters to populate the attributes: firstCustomer.SetName("Eleanor") ' populate first instance firstCustomer.SetAddress("Atlanta") firstCustomer.SetPhoneNo(" ") secondCustomer.SetName("Mike") ' populate second instance secondCustomer.SetAddress("Boston") secondCustomer.SetPhoneNo(" ") thirdCustomer.SetName("JoAnn") ' populate third instance thirdCustomer.SetAddress("St. Louis") thirdCustomer.SetPhoneNo(" ") Object-Oriented Application Development Using VB .NET
244
Creating Multiple Instances
Each instance has Its own identity Its own attribute values The ability to respond to messages Statements to retrieve and display each customer’s name: ' display names of all three customers Console.WriteLine(firstCustomer.GetName()) Console.WriteLine(secondCustomer.GetName()) Console.WriteLine(thirdCustomer.GetName()) Object-Oriented Application Development Using VB .NET
245
Writing a Constructor Method
A method that is automatically invoked whenever an instance of a class is created using the keyword New Named New Written as a Sub procedure; cannot return a value Default constructor Created by VB .NET if the programmer does not write a constructor Does not do anything Consists of only a header and an End Sub statement Object-Oriented Application Development Using VB .NET
246
Writing a Constructor Method
Parameterized constructor Created by the programmer Can contain a parameter list to receive arguments that are used to populate the instance attributes Object-Oriented Application Development Using VB .NET
247
Writing a Constructor Method
Parameterized constructor for Customer: 'constructor (3 parameters) Public Sub New(ByVal aName As String, ByVal anAddress As String, ByVal aPhoneNo As String) SetName(aName) SetAddress(anAddress) SetPhoneNo(aPhoneNo) End Sub This constructor invokes setter methods to populate attributes Object-Oriented Application Development Using VB .NET
248
Writing a Constructor Method
Alternative design: constructor assigns values directly to attribute variables instead of invoking setter methods Public Sub New(ByVal aName As String, ByVal anAddress As String, ByVal aPhoneNo As String) name = aName address = anAddress phoneNo = aPhoneNo End Sub Object-Oriented Application Development Using VB .NET
249
Writing a TellAboutSelf Method
Good design: changes in one class should be insulated from outside classes to reduce maintenance requirements To accomplish this, a TellAboutSelf method can be used Can be invoked to retrieve all of the attribute values for an instance Places all the values in a String instance Returns the String instance to the invoking client Should have public accessibility Should be written as a Function procedure Object-Oriented Application Development Using VB .NET
250
Writing a TellAboutSelf Method
TellAboutSelf method for Customer 'TellAboutSelf method Public Function TellAboutSelf() As String Dim info As String info = "Name = " & GetName() & _ ", Address = " & GetAddress() & _ ", Phone No = " & GetPhoneNo() Return info End Function Object-Oriented Application Development Using VB .NET
251
Writing a Tester Class as a Form
In previous examples Tester classes were written as modules A console application was used to run them Another approach to writing tester classes: making them GUIs Form A visible GUI object Can have push buttons and other GUI objects Object-Oriented Application Development Using VB .NET
252
Writing a Tester Class as a Form
Object-Oriented Application Development Using VB .NET
253
Writing a Tester Class as a Form
When a button is clicked on a form, an event is created Event procedure or event handler A Sub procedure Executes when an event occurs Object-Oriented Application Development Using VB .NET
254
Object-Oriented Application Development Using VB .NET
Summary VB .NET has naming conventions for classes, methods, and variables Problem domain class definitions are written for each PD class Class definition: code that represents a class Accessor methods provide access to attribute values Set accessors, or setters, store values Get accessors, or getters, retrieve values Object-Oriented Application Development Using VB .NET
255
Object-Oriented Application Development Using VB .NET
Summary A property can also provide access to attributes Client objects invoke server methods to perform tasks A constructor, a special method, is automatically invoked whenever a class is instantiated TellAboutSelf, a custom method, retrieves all instance attribute values and returns them in a string Object-Oriented Application Development Using VB .NET
256
Adding Responsibilities to Problem Domain Classes
Chapter 7 Adding Responsibilities to Problem Domain Classes Object-Oriented Application Development Using VB .NET
257
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Write a new problem domain class definition Create custom methods Write class variables and methods Write overloaded methods Work with exceptions Object-Oriented Application Development Using VB .NET
258
Writing a New Problem Domain Class Definition
Slip class Attributes slipId slipWidth slipLength Custom method LeaseSlip Object-Oriented Application Development Using VB .NET
259
Writing a New Problem Domain Class Definition
Class definition of Slip Class header Public Class Slip Attribute definition statements Private slipId As Integer Private slipWidth As Integer Private slipLength As Integer Object-Oriented Application Development Using VB .NET
260
Writing a New Problem Domain Class Definition
Class definition of Slip (Continued) Parameterized constructor Enables attributes to be automatically populated whenever an instance is created Public Sub New(ByVal aSlipId As Integer, _ ByVal aSlipWidth As Integer, ByVal aSlipLength As Integer) Argument data types must be assignment compatible with parameter data types Object-Oriented Application Development Using VB .NET
261
Writing a New Problem Domain Class Definition
Class definition of Slip (Continued) Statements to populate the Slip attributes To avoid redundant code, setter methods are invoked instead of directly assigning the values 'invoke setter methods to populate attributes SetSlipId(aSlipId) SetSlipWidth(aSlipWidth) SetSlipLength(aSlipLength) Object-Oriented Application Development Using VB .NET
262
Writing a New Problem Domain Class Definition
Class definition of Slip (Continued) TellAboutSelf method Invokes the three getters Concatenates the returned values Returns the result Public Function TellAboutSelf() As String Dim info As String info = "Slip: Id = " & GetSlipId() & ", Width = " & GetSlipWidth() _ & ", Length = " & GetSlipLength() Return info End Function Object-Oriented Application Development Using VB .NET
263
Writing a New Problem Domain Class Definition
Class definition of Slip (Continued) TellAboutSelf method Polymorphic methods Two methods with the same name, residing in different classes, that behave differently Example: TellAboutSelf methods for Customer and Slip classes Setter and getter methods Object-Oriented Application Development Using VB .NET
264
Creating Custom Methods
Process data Accessor methods Store and retrieve attribute values LeaseSlip method A custom method Computes the lease fee for a slip Fees range from $800 to $1,500 depending on the slip’s width Object-Oriented Application Development Using VB .NET
265
Creating Custom Methods
LeaseSlip method A Function procedure Will return a value: the lease fee amount Has Public accessibility Can be invoked by any object Return data type: Single Will compute and return the lease fee, a dollar amount Method header: Public Function LeaseSlip() As Single Object-Oriented Application Development Using VB .NET
266
Creating Custom Methods
Select statement for computing lease fee: Dim fee As Single Select Case slipWidth Case 10 fee = 800 Case 12 fee = 900 Case 14 fee = 1100 Case 16 fee = 1500 Case Else fee = 0 End Select Return fee Object-Oriented Application Development Using VB .NET
267
Writing Class Variables and Methods
Instance variables and methods Each instance has a copy Class variables and methods Shared by all instances of the class Each instance does not have its own copy Declared using the keyword Shared Object-Oriented Application Development Using VB .NET
268
Writing Class Variables and Methods
Variable numberOfSlips can be used to track the total number of slips numberOfSlips variable Initialized to 0 Private accessibility Will be accessed only by methods within the Slip class Private Shared numberOfSlips As Integer = 0 Object-Oriented Application Development Using VB .NET
269
Writing Class Variables and Methods
Code added to the Slip constructor for the numberOfSlips variable 'increment shared attribute numberOfSlips += 1 Increments numberOfSlips each time a slip instance is created Object-Oriented Application Development Using VB .NET
270
Writing Class Variables and Methods
GetNumberOfSlips() method Returns the contents of numberOfSlips Written as a Function procedure Returns a value Written as a shared method Not associated with any individual instance Has Public accessibility Will be invoked by other classes Object-Oriented Application Development Using VB .NET
271
GetNumberOfSlips() method
'shared (class) method Public Shared Function GetNumberOfSlips() As Integer Return numberOfSlips End Function Object-Oriented Application Development Using VB .NET
272
Writing Overloaded Methods
Method signature: Name and parameter list A class definition can contain several methods with the same name, as long as their parameter lists differ VB .NET identifies a method by its signature, not only by its name Overloaded method: a method that has the same name as another method in the same class, but a different parameter list Object-Oriented Application Development Using VB .NET
273
Overloading a Constructor
Problem Most slips at Bradshaw Marina are 12 feet wide and 25 feet long, but a few have different widths and lengths Current Slip constructor requires three arguments: slipId, slipWidth, and slipLength Object-Oriented Application Development Using VB .NET
274
Overloading a Constructor
Solution Write a second Slip constructor that has only a single parameter for slipId Include statements to assign the default values of 12 and 25 to slipWidth and slipLength, respectively Object-Oriented Application Development Using VB .NET
275
Overloading a Constructor
Constants can be used for the default width and length values: 'constants Private Const DEFAULT_SLIP_WIDTH As Integer = 12 Private Const DEFAULT_SLIP_LENGTH As Integer = 25 Object-Oriented Application Development Using VB .NET
276
Overloading a Constructor
Code for second constructor: '1-parameter constructor 'Overloads keyword not used with constructors Public Sub New(ByVal aSlipId As Integer) 'invoke 3-parameter constructor, passing default values Me.New(aSlipId, DEFAULT_SLIP_WIDTH, DEFAULT_SLIP_LENGTH) End Sub Object-Oriented Application Development Using VB .NET
277
Overloading a Constructor
VB .NET determines which constructor to invoke by the argument list If the argument consists of three values Original constructor with three parameters is executed If the argument consists of a single value New constructor with one parameter is invoked Object-Oriented Application Development Using VB .NET
278
Overloading a Custom Method
Problem Bradshaw Marina permits a discounted lease fee under certain conditions Solution A second version of the LeaseSlip method that accepts a value for the percentage discount Will overload the original LeaseSlip method Object-Oriented Application Development Using VB .NET
279
Overloading a Custom Method
Two LeaseSlip methods in Slip, each with a different signature Original LeaseSlip has an empty parameter list Second LeaseSlip has a parameter variable named aDiscountPercent Object-Oriented Application Development Using VB .NET
280
Overloading a Custom Method
Header for new method Must contain the keyword Overloads Public Overloads Function LeaseSlip(ByVal aDiscountPercent As Single) _ As Single Object-Oriented Application Development Using VB .NET
281
Overloading a Custom Method
New method: 'overloaded custom method LeaseSlip if discount requested Public Overloads Function LeaseSlip(ByVal aDiscountPercent As Single) _ As Single 'invoke LeaseSlip() to get fee Dim fee As Single = Me.LeaseSlip() 'calculate and return discount fee Dim discountFee As Single = fee * (100 - aDiscountPercent) / 100 Return discountFee End Function Object-Oriented Application Development Using VB .NET
282
Overloading a Custom Method
VB .NET will execute the appropriate method depending on the argument list If no argument is passed Original LeaseSlip method is invoked If an argument is coded Overridden method is executed Object-Oriented Application Development Using VB .NET
283
Working with Exceptions
An exception Used to notify the programmer of errors, problems, and other unusual conditions that may occur while the system is running An instance of the Exception class or one of its subclasses Object-Oriented Application Development Using VB .NET
284
Working with Exceptions
VB .NET uses five keywords to deal with exceptions Try Used by the client Catch Finally End Try Throw Used by the server Object-Oriented Application Development Using VB .NET
285
Working with Exceptions
Object-Oriented Application Development Using VB .NET
286
Data Validation for slipId
slipId value should be within the range of 1 through 50 SetSlipId method Data validation logic used to verify that slipId values are in the range of 1 through 50 Create and throw an exception instance if a value is outside the valid range Object-Oriented Application Development Using VB .NET
287
Data Validation for slipId
Constant MAXIMUM_NUMBER_OF_SLIPS Simplifies future maintenance: should Bradshaw Marina decide to have docks with more than 50 slips Private Const MAXIMUM_NUMBER_OF_SLIPS As Integer = 50 Object-Oriented Application Development Using VB .NET
288
Data Validation for slipId
If statement Determines if aSlipId is within valid range If a value is outside acceptable range An instance of Exception class is created and thrown Object-Oriented Application Development Using VB .NET
289
Data Validation for slipId
Public Sub SetSlipId(ByVal aSlipId As Integer) 'reject slipId if < 0 or > maximum If aSlipId < 1 Or aSlipId > MAXIMUM_NUMBER_OF_SLIPS Then Throw New Exception("Slip Id not between 1 and " _ & MAXIMUM_NUMBER_OF_SLIPS) Else slipId = aSlipId End If End Sub Object-Oriented Application Development Using VB .NET
290
Data Validation for slipWidth
Code must be added to the SetSlipWidth method to verify that the width parameter is a valid width value: 10, 12, 14, or 16 VALID_SLIP_WIDTHS An integer array Stores valid width values Private Shared ReadOnly VALID_SLIP_WIDTHS As Integer() = {10, 12, 14, 16} Object-Oriented Application Development Using VB .NET
291
Data Validation for slipWidth
Validation logic Will iterate the array, seeking a match between the parameter value received (aSlipWidth) and an array value If a matching value is found Parameter is valid If the end of the array is reached without finding a matching value Parameter contains an invalid value An exception is created and thrown Object-Oriented Application Development Using VB .NET
292
Data Validation for slipWidth
Validation logic: Dim validWidth As Boolean = False 'search for a valid width Dim i As Integer For i = 0 To VALID_SLIP_WIDTHS.Length - 1 If aSlipWidth = VALID_SLIP_WIDTHS(i) Then validWidth = True Next i Object-Oriented Application Development Using VB .NET
293
Data Validation for slipWidth
If statement to test validWidth If true Width attribute is populated with parameter value If not true An instance of Exception is created and thrown 'if a valid width found, set value If validWidth Then slipWidth = aSlipWidth Else 'else throw exception Throw New Exception("Invalid Slip Width") End If Object-Oriented Application Development Using VB .NET
294
Object-Oriented Application Development Using VB .NET
Catching Exceptions If a method that might throw an exception is invoked, the invoking code must be prepared to catch the exception .NET CLR will terminate processing if an exception is thrown and not caught Try block structure Keyword Try Code containing invoking statement or statements Keyword End Try Object-Oriented Application Development Using VB .NET
295
Object-Oriented Application Development Using VB .NET
Catching Exceptions Catch block Receives and deals with an exception Must specify a parameter variable to receive a reference to the exception instance Dim aSlip As Slip Try 'force an exception with invalid slipID (150) aSlip = New Slip(150, 10, 25) Console.WriteLine(aSlip.TellAboutSelf()) Catch theException As Exception Console.WriteLine("An exception was caught: " & _ theException.ToString()) End Try Object-Oriented Application Development Using VB .NET
296
Object-Oriented Application Development Using VB .NET
Catching Exceptions Finally block Used to add statements that are to be executed whether or not an exception was caught Finally Console.WriteLine("Finally block always executes") Object-Oriented Application Development Using VB .NET
297
Object-Oriented Application Development Using VB .NET
Summary Custom methods: methods which process data Class variables and methods are associated with the class instead of individual instances A new instance is given a copy of all instance variables and access to instance methods A new instance does not get a copy of class variables and methods A method signature consists of the method name and its parameter list VB .NET identifies a method by its signature Object-Oriented Application Development Using VB .NET
298
Object-Oriented Application Development Using VB .NET
Summary An overloaded method has the same name as another method in the same class, but a different signature Exceptions notify the programmer of errors, problems, and other unusual conditions that may occur while the system is running Keywords dealing with exceptions: Try, Catch, Finally, End Try, and Throw CLR terminates processing if an exception is thrown and not caught Object-Oriented Application Development Using VB .NET
299
Understanding Inheritance and Interfaces
Chapter 8 Understanding Inheritance and Interfaces Object-Oriented Application Development Using VB .NET
300
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Implement the Boat generalization/specialization class hierarchy Understand abstract and final classes and the MustInherit and NotInheritable keywords Override a superclass method Understand private versus protected access Object-Oriented Application Development Using VB .NET
301
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Explore the Lease subclasses and abstract methods Understand and use interfaces Use custom exceptions Understand the Object class and inheritance Object-Oriented Application Development Using VB .NET
302
Implementing the Boat Generalization/Specification Hierarchy
Boat class Stores information about a boat’s State registration number Length Manufacturer Model year Object-Oriented Application Development Using VB .NET
303
Implementing the Boat Generalization/Specification Hierarchy
Boat class Parameterized constructor Accepts values for all four attributes Eight standard accessor methods Four setter methods Four getter methods TellAboutSelf method Object-Oriented Application Development Using VB .NET
304
Testing the Boat Superclass with a Windows Form
A Windows application and a Windows form with buttons can be used to test all problem domain classes Windows form testers Accomplish the same objective as a class module To systematically test each problem domain class to demonstrate that all functionality works as intended Object-Oriented Application Development Using VB .NET
305
Using the Inherits Keyword to Create the Sailboat Subclass
Generalization/specialization hierarchy Superclass Includes attributes and methods that are common to specialized subclasses Instances of the subclasses Inherit attributes and methods of the superclass Include additional attributes and methods Object-Oriented Application Development Using VB .NET
306
Using the Inherits Keyword to Create the Sailboat Subclass
Superclass Boat class Four attributes and eight accessor methods Subclasses Sailboat Three additional attributes Powerboat Two additional attributes Object-Oriented Application Development Using VB .NET
307
Using the Inherits Keyword to Create the Sailboat Subclass
Object-Oriented Application Development Using VB .NET
308
Using the Inherits Keyword to Create the Sailboat Subclass
Used in the class header to implement a subclass Indicates which class the new class is extending Example: Class header to define the Sailboat class as a subclass of Boat: Public Class Sailboat Inherits Boat Object-Oriented Application Development Using VB .NET
309
Using the Inherits Keyword to Create the Sailboat Subclass
Class definition of a subclass Includes any attributes and methods in addition to those inherited from the superclass Sailboat constructor Accepts seven parameters Four for attributes defined in the Boat superclass Three for additional attributes defined in Sailboat Object-Oriented Application Development Using VB .NET
310
Using the Inherits Keyword to Create the Sailboat Subclass
Sailboat constructor MyBase.New call Used to set attributes for registration number, length, manufacturer, and year Invokes constructor of the superclass Must be the first statement in the constructor Required unless the superclass includes a default constructor without parameters Sailboat set accessor methods Used to set the three remaining attribute values Object-Oriented Application Development Using VB .NET
311
Adding a Second Subclass – Powerboat
Powerboat class Extends the Boat class Declares two attributes: numberEngines fuelType Constructor expects six parameters Four required by Boat Two additional attributes for Powerboat Object-Oriented Application Development Using VB .NET
312
Adding a Second Subclass – Powerboat
Once the boats are created Four getter methods inherited from Boat Can be invoked for both sailboats and powerboats Three additional getter methods of Sailboat Not present in powerboats Two additional getter methods of Powerboats Not present in sailboats Object-Oriented Application Development Using VB .NET
313
Understanding Abstract and Final Classes
Concrete classes Classes that can be instantiated Examples Sailboat class Powerboat class Object-Oriented Application Development Using VB .NET
314
Using the MustInherit Keyword
Abstract class Not intended to be instantiated Only used to extend into subclasses Used to facilitate reuse MustInherit keyword Used in class header to declare an abstract class Example: Class header to make the Boat class abstract: Public MustInherit Class Boat Object-Oriented Application Development Using VB .NET
315
Using the NotInheritable Keyword
A Final class A class that cannot be extended Created for security purposes or efficiency Created using the NotInheritable keyword Example Class header for the Powerboat class : Public NotInheritable Class Powerboat Inherits Boat Object-Oriented Application Development Using VB .NET
316
Overriding a Superclass Method
Method overriding Method in subclass will be invoked instead of method in the superclass if both methods have the same signature Allows the subclass to modify the behavior of the superclass Object-Oriented Application Development Using VB .NET
317
Overriding a Superclass Method
Method overriding vs. method overloading Overloading Two or more methods in the same class have the same name but a different return type or parameter list Overriding Methods in both the superclass and subclass have the same signature Object-Oriented Application Development Using VB .NET
318
Overriding the Boat TellAboutSelf Method
Demonstrates method overriding Used to make it easier to get information about an instance of the class Overridable keyword Included in method header to make a method overridable Object-Oriented Application Development Using VB .NET
319
Overriding the Boat TellAboutSelf Method
To override the TellAboutSelf method Use the same method signature in the subclass, except for using Overrides keyword in place of Overridable keyword Once a method is overriden Statements in the subclass method control what system does when a sailboat instance is asked to tell about itself Method in Boat is ignored Object-Oriented Application Development Using VB .NET
320
Overriding and Invoking a Superclass Method
Sometimes the programmer needs to override a method by extending what the method does For example Powerboat TellAboutSelf method invokes the superclass method using MyBase keyword Superclass method name Object-Oriented Application Development Using VB .NET
321
Overriding, Polymorphism, and Dynamic Binding
Objects of different classes can respond to the same message in their own way Dynamic binding Used to resolve which method to invoke when the system runs and finds more than one method with the same name Provides flexibility when adding new subclasses that override superclass methods Object-Oriented Application Development Using VB .NET
322
Understanding Private Versus Protected Access
Declaring attributes as private Done by using Private keyword No other object can directly read or modify the values Other objects must use methods of the class to get or set values Ensures encapsulation and information hiding Limits the ability of an instance of a subclass to directly access attributes defined by the superclass Object-Oriented Application Development Using VB .NET
323
Understanding Private Versus Protected Access
Declaring attributes as Protected Done by using Protected keyword Values can be directly accessed by subclasses Local variable Accessible only to statements within a method where it is declared Exists only as long as the method is executing Does not need to be declared as private, protected, friend, or public Object-Oriented Application Development Using VB .NET
324
Understanding Private Versus Protected Access
Methods Private methods Can only be invoked from a method within the class Cannot be invoked even by subclass methods Protected methods Can be invoked by a method in a subclass Object-Oriented Application Development Using VB .NET
325
Introducing the Lease Subclasses and Abstract Methods
Lease class Subclasses AnnualLease DailyLease Attributes Amount: a numeric value Start date: a reference variable End date : a reference variable Defined as abstract Includes MustInherit keyword in header Object-Oriented Application Development Using VB .NET
326
Introducing the Lease Subclasses and Abstract Methods
Object-Oriented Application Development Using VB .NET
327
Introducing the Lease Subclasses and Abstract Methods
Lease class constructor Accepts one parameter A reference to a DateTime instance for start date of the lease Sets end date to Nothing Sets amount of the lease to zero Subclasses set end date and calculate amount depending on type of the lease Object-Oriented Application Development Using VB .NET
328
Adding an Abstract Method to Lease
Sometimes it is desirable to require all subclasses to include a method All Lease subclasses need a CalculateFee method Subclasses are responsible for determining what the lease amount will be Necessary for polymorphism Object-Oriented Application Development Using VB .NET
329
Adding an Abstract Method to Lease
A method without any statements that must be overridden by all subclasses Declared by using MustOverride keyword in method header For example CalculateFee method of the Lease class Object-Oriented Application Development Using VB .NET
330
Implementing the AnnualLease Subclass
AnnualLease subclass attributes balanceDue The amount of the annual lease that remains unpaid payMonthly A Boolean Indicates whether monthly payments will be made for the annual lease Object-Oriented Application Development Using VB .NET
331
Implementing the AnnualLease Subclass
If payMonthly is true balanceDue is initially set to eleven-twelfths of the lease amount If payMonthly is false balanceDue will be zero Object-Oriented Application Development Using VB .NET
332
Implementing the DailyLease Subclass
A subclass of the Lease class Used when a customer leases a slip for a short time Additional attribute Number of days of the lease Calculated based on the start date and end date Object-Oriented Application Development Using VB .NET
333
Understanding and Using Interfaces
An interface Defines abstract methods and constants that must be implemented by classes that use the interface Can be used to ensure that an instance has a defined set of methods Object-Oriented Application Development Using VB .NET
334
Understanding and Using Interfaces
Component-based development Components interact in a system using a well-defined interface Components might be built using a variety of technologies Interfaces Define how components can be used Play an important role in developing component-based systems Object-Oriented Application Development Using VB .NET
335
Understanding and Using Interfaces
A VB .NET class Can inherit from only one superclass Can implement one or more interfaces Interfaces allow VB .NET subclasses a form of multiple inheritance Multiple inheritance Ability to inherit from more than one class A subclass is part of two or more generalization/specialization hierarchies Object-Oriented Application Development Using VB .NET
336
Creating a VB .NET Interface
Name (by convention) Begins with a capital letter “I” Uses the word “interface” Header Uses Interface keyword, followed by the interface name Methods Include no code Object-Oriented Application Development Using VB .NET
337
Creating a VB .NET Interface
A class can implement an interface by adding the following to the class header: Implements keyword Name of the interface Object-Oriented Application Development Using VB .NET
338
Implementing More Than One Interface
To implement more than one interface Use Implements keyword in the class header Separate multiple interface names by commas For example: Public Class DailyLease Inherits Lease Implements ILeaseInterface, ICompanyInterface Object-Oriented Application Development Using VB .NET
339
Using Custom Exceptions
NotInheritable keyword Any class that is not declared NotInheritable can be extended Custom exception An exception written specifically for an application An example of extending a built-in class Object-Oriented Application Development Using VB .NET
340
Defining LeasePaymentException
A custom exception Created by defining a class that extends the Exception class Designed for use by the AnnualLease class Thrown if payment is invalid Object-Oriented Application Development Using VB .NET
341
Throwing a Custom Exception
RecordLeasePayment method A custom method Records a payment Expects to receive the amount of the payment Throws a LeasePaymentException instance if payment amount is not valid Object-Oriented Application Development Using VB .NET
342
Understanding the Object Class and Inheritance
Extended by all classes in VB .NET Defines basic functionality that other classes need in VB .NET ToString method A method of the Object class Inherited by all classes By default, returns a string representation of the class name Overridden by other classes to provide more specific information Object-Oriented Application Development Using VB .NET
343
Understanding the Object Class and Inheritance
Some other methods of the Object class Equals GetHashCode GetType ReferenceEquals The Default New constructor Object-Oriented Application Development Using VB .NET
344
Object-Oriented Application Development Using VB .NET
Summary Generalization/specialization hierarchies show superclasses and subclasses The subclass inherits attributes and methods of the superclass An abstract class: a class that is not instantiated; exists only to serve as a superclass A final class: a class that cannot be extended Object-Oriented Application Development Using VB .NET
345
Object-Oriented Application Development Using VB .NET
Summary An abstract method in a superclass must be implemented by all the subclasses An interface can be used to require that classes contain specific methods Custom exceptions can provide detailed information following an exception In VB .NET, the Object class is the superclass of all classes Object-Oriented Application Development Using VB .NET
346
Implementing Association Relationships
Chapter 9 Implementing Association Relationships Object-Oriented Application Development Using VB .NET
347
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Identify association relationships on Bradshaw Marina’s class diagram Associate VB .NET classes in a one-to-one relationship Add functionality to the Boat class Object-Oriented Application Development Using VB .NET
348
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Associate Dock and Slips in a one-to-many relationship Add the Boat and Customer classes to the Slip example Create and use an association class—Lease Object-Oriented Application Development Using VB .NET
349
Object-Oriented Application Development Using VB .NET
Identifying Association Relationships on Bradshaw Marina’s Class Diagram Association relationships Show how instances of classes are associated, or connected, to each other Indicate that the system requires information about these associations Can be used to navigate from instance to instance following the association Object-Oriented Application Development Using VB .NET
350
Object-Oriented Application Development Using VB .NET
Identifying Association Relationships on Bradshaw Marina’s Class Diagram In a class diagram An association relationship Appears as a line connecting classes Multiplicity of the association Indicated by numbers written at both ends of the line Object-Oriented Application Development Using VB .NET
351
Object-Oriented Application Development Using VB .NET
Identifying Association Relationships on Bradshaw Marina’s Class Diagram Association relationships in the Bradshaw class diagram: A customer owns a boat A boat is owned by a customer A boat is assigned to a slip A slip contains a boat A dock contains many slips A slip is attached to a dock A slip is leased to a customer (Lease is an association class) A customer leases a slip (Lease is an association class) Object-Oriented Application Development Using VB .NET
352
Object-Oriented Application Development Using VB .NET
Identifying Association Relationships on Bradshaw Marina’s Class Diagram Object-Oriented Application Development Using VB .NET
353
Object-Oriented Application Development Using VB .NET
Identifying Association Relationships on Bradshaw Marina’s Class Diagram Lease class An example of an association class Exists because of the relationship between a slip and a customer In the class diagram Shown as a class connected by a dashed line to an association between Slip and Customer Object-Oriented Application Development Using VB .NET
354
Associating VB .NET Classes in a One-to-One Relationship
Association relationship between Customer and Boat Has two “directions” A customer owns a boat A boat is owned by a customer Each direction of the relationship Must be defined separately by the system developer Must be handled separately with VB .NET Object-Oriented Application Development Using VB .NET
355
Associating VB .NET Classes in a One-to-One Relationship
To implement an association relationship in VB .NET Use a reference variable as an attribute of a class A reference variable points to an actual instance Object-Oriented Application Development Using VB .NET
356
Associating VB .NET Classes in a One-to-One Relationship
Object-Oriented Application Development Using VB .NET
357
Associating VB .NET Classes in a One-to-One Relationship
A Customer reference variable Points to a Customer instance If added as an attribute in the Boat class, each Boat instance can Point to a Customer instance Invoke the customer’s methods Object-Oriented Application Development Using VB .NET
358
Associating VB .NET Classes in a One-to-One Relationship
A Boat reference variable Points to a Boat instance If added as an attribute in the Customer class, each Customer instance can Point to a Boat instance Invoke the boat’s methods Object-Oriented Application Development Using VB .NET
359
Modifying the Customer Class
Modifying the Customer class implements one direction of the association relationship From Customer to Boat theBoat attribute A Boat reference variable Added to the Customer class Used to implement a one-to-one association relationship with the Boat class Object-Oriented Application Development Using VB .NET
360
Modifying the Customer Class
Accessor methods SetBoat Accepts a Boat reference as a parameter Assigns the reference to the attribute GetBoat Returns the Boat reference Object-Oriented Application Development Using VB .NET
361
Modifying the Customer Class
Constructor Sets the Boat reference variable to Nothing using the SetBoat method Once Customer instance is created Boat reference variable can be set to an actual Boat reference Object-Oriented Application Development Using VB .NET
362
Modifying the Boat Class
Modifying the Boat class implements the other direction of the association relationship A boat is owned by a customer theCustomer attribute A Customer reference variable Added to the Boat class Used to implement a one-to-one association relationship with the Customer class Object-Oriented Application Development Using VB .NET
363
Modifying the Boat Class
Accessor methods GetCustomer Returns the Customer reference SetCustomer Accepts a Customer reference as a parameter Assigns the reference to the attribute Object-Oriented Application Development Using VB .NET
364
Adding Functionality to the Boat Class
Functionality of classes that have association relationships can be increased AssignBoatToCustomer custom method Added in Boat Establishes the association between Boat and Customer in both directions in one step Object-Oriented Application Development Using VB .NET
365
Adding Functionality to the Boat Class
Mandatory association between Boat and Customer Possible because Bradshaw Marina does not want to keep information about a boat if its owner is not a customer Done by Adding a Customer reference parameter to the Boat constructor Object-Oriented Application Development Using VB .NET
366
Adding Functionality to the Boat Class
Modified Boat TellAboutSelf method Returns information about Boat Customer Possible because A boat must be associated with a customer Object-Oriented Application Development Using VB .NET
367
Associating Docks and Slips: A One-to-Many Association Relationship
Association relationship between Slip and Dock Two directions of the relationship One-to-one A slip is attached to a dock Association relationship between Dock and Slip One-to-many A dock contains many slips Object-Oriented Application Development Using VB .NET
368
Associating Docks and Slips: A One-to-Many Association Relationship
To implement A one-to-one association relationship between Slip and Dock Use the technique used to implement the Customer and Boat associations A one-to-many association relationship between Dock and Slip Requires that a dock instance have reference variables for more than one slip Use an ArrayList in the Dock class to hold many Slip reference variables Object-Oriented Application Development Using VB .NET
369
Associating Docks and Slips: A One-to-Many Association Relationship
ArrayList class Can be used to instantiate a container that can hold many reference variables Has methods which can be used to Add Slip references Retrieve Slip references Object-Oriented Application Development Using VB .NET
370
Introducing the Dock Class
Four previous attributes An ID number A location Two Boolean variables indicating Whether the dock has electricity Whether the dock has water Fifth attribute slips An ArrayList Implements the one-to-many association relationship Object-Oriented Application Development Using VB .NET
371
Introducing the Dock Class
Dock class constructor Sets values for the four attributes Instantiates the new ArrayList Assigns the new ArrayList to the slips attribute GetSlips A getter method Returns the slips reference variable Object-Oriented Application Development Using VB .NET
372
Introducing the Dock Class
AddSlip custom method Used to add a slip to the dock Invoked by the Slip AddSlipToDock method Contains the slips.Add(aSlip) statement Used to add a Slip reference to the ArrayList referenced by the variable slips Object-Oriented Application Development Using VB .NET
373
Associating the Slip Class with Dock
Modifications to the Slip class to implement the mandatory one-to-one association relationship theDock attribute A Dock reference variable Accessor methods for the Dock reference attribute Object-Oriented Application Development Using VB .NET
374
Associating the Slip Class with Dock
Modifications to the Slip class (Continued) Modified constructor Expects a Dock reference parameter Result: When a slip is instantiated, it must be associated with a dock Invokes the slip’s AddSlipToDock method AddSlipToDock method establishes the association in both directions by Invoking the dock’s AddSlip method using the Me keyword Object-Oriented Application Development Using VB .NET
375
Associating the Slip Class with Dock
Modifications to the Slip class (Continued) A TellAboutSelf method Returns information about The slip The slip’s dock Object-Oriented Application Development Using VB .NET
376
Adding the Boat and Customer Classes to the Slip Example
Association relationship between Slip and Boat Modifications to the Slip class A Boat reference attribute Accessor methods GetBoat SetBoat Modifications to the Boat class A Slip reference attribute AssignBoatToSlip method Object-Oriented Application Development Using VB .NET
377
Adding the Boat and Customer Classes to the Slip Example
To include the Customer class in this example Boat class does not need to be modified It is already designed to associate with a customer Given a Customer reference Can navigate to find The customer’s boat The boat’s slip The slip’s dock Object-Oriented Application Development Using VB .NET
378
Adding the Boat and Customer Classes to the Slip Example
Given a Dock reference Can navigate to Each slip The slip’s boat The customer who owns the boat Object-Oriented Application Development Using VB .NET
379
Creating and Using an Association Class – Lease
Lease class An association class A Lease is like an association between a customer and a slip, but with attributes for Start date End date Amount of lease, and so on Subclasses AnnualLease DailyLease Object-Oriented Application Development Using VB .NET
380
Creating and Using an Association Class – Lease
Modifications to the Lease superclass A Slip reference attribute A Customer reference attribute Accessor methods AnnualLease class A subclass of Lease Inherits the association between Lease and Slip Lease and Customer Object-Oriented Application Development Using VB .NET
381
Creating and Using an Association Class – Lease
No modifications needed for the Boat class Reason: Boat is not directly associated with Lease Modifications to the Customer class A Lease reference attribute Accessor methods Object-Oriented Application Development Using VB .NET
382
Creating and Using an Association Class – Lease
Modifications to the Slip class A Lease reference attribute Accessor methods LeaseAnnualSlip method Creates an AnnualLease instance Object-Oriented Application Development Using VB .NET
383
Object-Oriented Application Development Using VB .NET
Summary Association relationships are shown on the class diagram as lines connecting classes Association relationships are implemented in two directions that must be considered separately Association relationships can be optional or mandatory One-to-one association relationships are implemented by including a reference variable as an attribute in one class that points to an instance of another class Object-Oriented Application Development Using VB .NET
384
Object-Oriented Application Development Using VB .NET
Summary One-to-many association relationships are implemented using an ArrayList that contains a collection of reference variables Association relationships can be directly navigated by writing one statement with multiple method calls that are executed from left to right An association class exists because of a relationship between two classes, such as Lease between Slip and Customer Object-Oriented Application Development Using VB .NET
385
VB .NET GUI Components Overview
Chapter 10 VB .NET GUI Components Overview Object-Oriented Application Development Using VB .NET
386
Object-Oriented Application Development Using VB .NET
Objectives In this chapter, you will: Learn about the GUI classes in VB .NET Understand the code generated by VB .NET Handle VB .NET events Work with additional GUI controls Object-Oriented Application Development Using VB .NET
387
Introducing the GUI Classes in VB .NET
Form Instance of the Form class Consists of GUI controls, such as Buttons Labels Text boxes Check boxes Radio buttons Tab pages Menu items Form class Member of the System.Windows.Forms namespace Object-Oriented Application Development Using VB .NET
388
Introducing the GUI Classes in VB .NET
Object-Oriented Application Development Using VB .NET
389
Introducing the GUI Classes in VB .NET
Component class Base class for all GUI components An instance of a component does not have a visible, graphical representation Control class A subclass of Component An instance of a control has a visible, graphical representation Object-Oriented Application Development Using VB .NET
390
Understanding the Code Generated by VB .NET
Actions involved in visual programming Creating a form Setting properties of the form Adding controls and components to the form Setting properties of controls and components Adding the code to handle events As the programmer adds controls and modifies properties, VB .NET generates the code Object-Oriented Application Development Using VB .NET
391
Exploring the FormDemo Program
Contains A label A button When the button is pressed, a message box appears Object-Oriented Application Development Using VB .NET
392
Exploring the FormDemo Program
FormDemo class An instance of Form Inherits methods from ContainerControl ScrollableControl Control Component Object-Oriented Application Development Using VB .NET
393
Exploring the FormDemo Program
FormDemo class definition Specifies that the FormDemo class inherits from the Form class Defines the constructor Defines the Dispose method Dispose method is a destructor Releases system resources when the program ends Object-Oriented Application Development Using VB .NET
394
Exploring the FormDemo Program
FormDemo class definition (Continued) Declares an instance of the IContainer class IContainer: an interface that provides functionality for containers Container: an object that holds other components Declares controls that were created visually in Design window Object-Oriented Application Development Using VB .NET
395
Exploring the FormDemo Program
FormDemo class definition (Continued) Defines the InitializeComponent method InitializeComponent method Instantiates the label and button instances Calls the SuspendLayout method Sets the properties of the label, button and form instances Defines the event handler Object-Oriented Application Development Using VB .NET
396
Object-Oriented Application Development Using VB .NET
Handling VB .NET Events GUI controls have associated event procedures The process of creating event procedures Double-click a control in the Forms Designer window VB .NET inserts the method header for the most commonly used event procedure for that control Supply details that determine how the procedure responds to the event Object-Oriented Application Development Using VB .NET
397
Reviewing Forms, Buttons, and Labels
GUI controls Subclasses of the Control class Inherit properties, methods, and events from the Control class Have additional methods and properties Help facility Contains information about the methods and properties of GUI controls Object-Oriented Application Development Using VB .NET
398
Using Text Boxes and Combo Boxes
Display textual information to the user Enable input of text from the keyboard Functionality provided by the TextBox class Combo boxes Extend the functionality of a text box Allow the user to: Type a value Select an item from a predetermined list of values Functionality provided by the ComboBox class Object-Oriented Application Development Using VB .NET
399
Using Text Boxes and Combo Boxes
Object-Oriented Application Development Using VB .NET
400
Using Check Boxes and Radio Buttons
Provide the ability to select from options Have two states at any given point in time Checked (selected) Not checked (not selected) Functionality provided by the CheckBox and RadioButton classes Object-Oriented Application Development Using VB .NET
401
Using Check Boxes and Radio Buttons
A check box Appears as a small white box Usually includes a label that identifies its purpose The caption (or label) is set by the Text property When selected A check mark appears in the box Multiple check boxes There is no requirement that any check box be checked Any or all of the check boxes may be checked simultaneously Object-Oriented Application Development Using VB .NET
402
Using Check Boxes and Radio Buttons
Appear as small white circles Have captions (or labels) that identify their purpose When selected A black dot appears within the circle A group of radio buttons Represents a set of related options Options are mutually exclusive: one and only one of the options may be selected at any given time Object-Oriented Application Development Using VB .NET
403
Using Group Boxes and Panels
Containers used to visually and logically organize groups of related controls A group box Includes a border (or frame) Does not include scroll bars Usually has a caption Object-Oriented Application Development Using VB .NET
404
Using Group Boxes and Panels
A panel Does not include a border by default May include scroll bars Does not have captions Nested panels and group boxes A group box or panel may contain other group boxes or panels Object-Oriented Application Development Using VB .NET
405
Using Group Boxes and Panels
A common use of group boxes and panels Can be used to group a set of radio buttons Mutually exclusive behavior is enforced separately for each group Object-Oriented Application Development Using VB .NET
406
Using List Boxes and Checked List Boxes
Provide the ability to select one or more items from a predetermined list of values List boxes Instances of the ListBox class Enable the user (by default) to select one item from the list Selection of multiple list items can be enabled by setting the SelectionMode property Object-Oriented Application Development Using VB .NET
407
Using List Boxes and Checked List Boxes
Instances of the CheckedListBox class Include a check box to the left of each item in the list By default, allow the selection of multiple items in the list When an item is selected A check mark appears in the corresponding check box Object-Oriented Application Development Using VB .NET
408
Using Tree Views and Tree Nodes
A tree view Supported by the TreeView class Displays a group of hierarchically related items An item (or tree node) Represented as an instance of the TreeNode class Appears as an expandable outline Object-Oriented Application Development Using VB .NET
409
Using Tree Views and Tree Nodes
Object-Oriented Application Development Using VB .NET
410
Using Date/Time Pickers
A date/time picker control An instance of the DateTimePicker class Used to Select a date and time from a calendar Display the date and time in a number of different formats Object-Oriented Application Development Using VB .NET
411
Using Date/Time Pickers
Object-Oriented Application Development Using VB .NET
412
Using Tab Controls and Tab Pages
A tab control An instance of the TabControl class Provides the functionality for a set of tab pages Tab pages are useful when A form requires a large number of controls Those controls can easily be grouped into logical subsets Object-Oriented Application Development Using VB .NET
413
Using Tab Controls and Tab Pages
Each tab page An instance of the TabPage class (a subclass of Panel) Contains A subset of the controls A tab identifying its purpose Object-Oriented Application Development Using VB .NET
414
Using Main Menus and Menu Items
MainMenu and MenuItem classes Used to create a set of menus and submenus for a form Main menu control Container for the menu structure Menu items Represent individual menu choices within the menu structure Object-Oriented Application Development Using VB .NET
415
Object-Oriented Application Development Using VB .NET
Summary Component is a superclass of all GUI classes Control is a superclass of all visible components Forms are containers for other components Text boxes can be used to display and input data Combo boxes can be used to Display and input text Select from a predefined list of values Check boxes and radio buttons enable users to select (deselect) from a list of options Object-Oriented Application Development Using VB .NET
416
Object-Oriented Application Development Using VB .NET
Summary Tree views and tree nodes display a group of hierarchically related data Date/time pickers enable users to select a date from a calendar Tab controls and tab pages are useful when a form requires a large number of controls Main menus and menu items allow you to create a set of menus and submenus Object-Oriented Application Development Using VB .NET
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.