Professional Documents
Culture Documents
Lesson08 Class Object
Lesson08 Class Object
Lesson08 Class Object
Microsoft Visual
Basic .NET, Introduction
to Programming
1
Objectives
2
Vocabulary
3
Maximum Effect with Minimum Effort
4
Object-Oriented Programming (OOP )
6
Data Hiding
7
Inheritance
8
Polymorphism
9
Operator Overloading
10
The Object Browser
11
The Object Browser
12
The Find Symbol Dialog Box
13
Creating a Class
16
Note
17
Computer Ethics
18
Adding an Event
20
Summary
Programmers want better programming environments, cross-
platform applications, and reusable code modules.
Visual Basic is the root language of many Microsoft products,
including Microsoft Office.
Object-oriented programming (OOP) focuses on creating
objects that include data and the operations performed on the
data.
Data encapsulation, part of the OOP paradigm, is the ability of
an object to hide data and methods from the user or even the
programmer. This protects data from accidental alteration.
Inheritance is the ability of an OOP class to inherit properties
and methods from other classes.
21
Summary
Polymorphism is the ability to define multiple uses for the same
operators and methods.
You create objects from the templates provided by classes.
The Object Browser lets the programmer look at classes and
the properties of the object created from the classes.
You add class definitions to a project by selecting Project | Add
Class from the menu bar.
Public variables declared in the Declarations section of the
class definition become properties of objects created with the
new class.
22
Summary
Private variables declared in the Declarations section of a class
definition are available within the definition but cannot be
accessed outside the definition.
The program uses Property procedures to gather and provide
properties to objects. The program also uses the procedures to
modify or process the properties.
The StrConv( ) function can be used to convert an input string
to a string where the first character is capitalized and the other
characters are lowercase.
A new object created from a class is an instance, or an
instantiation, of the class.
You can save objects in text files by saving each part of the
object as text in the file.
23
Summary
Public procedures and functions recorded in a class definition
become the methods of the objects created with the class.
A business rule is a rule of the workplace written into the code
of a program. When put into class definitions, business rules
are easy to manage and implement.
The SelectedIndex property of a list box contains the index
value of the item currently selected in the list.
To add an event to a class module, first declare the event in the
Declarations section of the class definition, then write code to
raise the event. The code initiates the event when some
condition is satisfied (or not satisfied) in the class definition.
24
Summary
To use event definitions in a class definition, use the
WithEvents keyword in an application to declare the objects of
that class.
The ByVal keyword in a parameter list sends a parameter's
value to a function, not the parameter's address.
The program uses the RaiseEvent statement in a Class
definition to fire an event procedure.
Class definitions are at their best when used to hide the details
of program operations from a programmer and provide the
programmer with an easy-to-use interface to the data in the
objects created from the class definition.
25