0041 Course Oop in VB Dotnet
0041 Course Oop in VB Dotnet
Oriented Programming
in Visual Basic .NET
Cont ent s
Over view 1
Defining Classes 2
Creat ing and Dest roying Obj ect s 16
Dem onst rat ion: Creat ing Classes 23
Lab 5.1: Cr eat ing t he Cust om er Class 24
I nherit ance 31
Dem onst rat ion: I nherit ance 43
I nt erfaces 44
Dem onst rat ion: I nt er faces and
Poly m or phism 50
Wor k ing w it h Classes 51
Lab 5.2: I nher it ing t he Pack age Class 65
Review 74
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual
property rights covering subject matter in this document. Except as expressly provided in any
written license agreement from Microsoft, the furnishing of this document does not give you any
license to these patents, trademarks, copyrights, or other intellectual property.
Microsoft, MS-DOS, Windows, Windows NT, ActiveX, BizTalk, FrontPage, IntelliSense, JScript,
Microsoft Press, Outlook, PowerPoint, Visio, Visual Basic, Visual C++, Visual C#, Visual
InterDev, Visual Studio, and Windows Media are either registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries.
The names of actual companies and products mentioned herein may be the trademarks of their
respective owners.
Module 5: Object-Oriented Programming in Visual Basic .NET iii
Instructor Notes
Presentation: This module provides students with the knowledge required to create object-
90 Minutes oriented applications that use many of the new features of Microsoft®
Visual Basic ® .NET, such as inheritance, overloading, shared members, and
Labs: event handling.
105 Minutes
In the first lab, students will create part of the Customer class for the Cargo
system that they designed in Lab 4.1, Creating Diagrams from Use Cases. They
will define the properties, methods, and constructors, based on those shown in
Lab 4.1. Finally, they will write the code in a form to test the Customer class.
In the second lab, students will create a base class called Package and a derived
class called SpecialPackage. The classes contain some pre-written code,
including the properties. Students will add methods to both classes and create
the inheritance relationship. They will then complete a pre-written form to test
their classes.
After completing this module, students will be able to:
n Define classes.
n Instantiate and use objects in client code.
n Create classes that use inheritance.
n Define interfaces and use polymorphism.
n Create shared members.
n Create class events and handle them from a client application.
iv Module 5: Object-Oriented Programming in Visual Basic .NET
Required Materials
To teach this module, you need the following materials:
n Microsoft PowerPoint® file 2373A_05.ppt
n Module 5, “Object-Oriented Programming in Visual Basic .NET”
n Lab 5.1, Creating the Customer Class
n Lab 5.2, Inheriting the Package Class
Preparation Tasks
To prepare for this module, you should:
n Read all of the materials for this module.
n Read the instructor notes and the margin notes for the module.
n Practice the demonstrations.
n Complete the labs.
Module 5: Object-Oriented Programming in Visual Basic .NET v
Demonstrations
This section provides demonstration procedures that will not fit in the margin
notes or are not appropriate for the student notes.
Creating Classes
å To examine the Employee class
1. Open the Classes.sln solution in the install folder\DemoCode\
Mod05\Classes folder.
2. View the code for the Employee class and point out the private variables,
the properties, and the multiple constructors. Specifically point out the
EmployeeId read-only property.