An object is an entity that stores data, has methods that manipulate the data, and can trigger events. A class is a template from which objects are created. A method specifies the way in which an object's data are manipulated. An event is a message sent by an object to signal the occurrence of a condition.
Each class is defined in a separate block of code starting with Class className and ending with End Class. Data are stored in member variables and accessed by procedures called properties.
A property routine contains a Get block to retrieve the value of a member variable or a Set block to assign a value to a member variable. These procedures can also be used to enforce constraints and carry out validation.
Visual Basic automatically invokes a New procedure when an object is created.
An object variable is declared with a statement of the form DimobjectNameAsclassName, and the object is created with a statement of the form objectName= NewclassName(arg1, arg2, ...). These two statements are often combined into the single statement DimobjectNameAs NewclassName(arg1, arg2, ...).
[Page 602]
Events are declared in the Declarations section of a class with a statement of the form Public Event UserDefinedEvent(arg1, arg2, ...) and triggered with a RaiseEvent statement. The declaration statement for the object must include the keyword WithEvents in order for the events coming from the object to be processed. The header of an event-handling procedure has the form Private Sub procedureName(par1, par2, ...) Handles objectName. UserDefinedEvent.
The properties, methods, and events of a class are referred to as its interface.
Inheritance, which is implemented with the keyword Inherits, allows a new class (called the derived or child class) to be created from an existing class (called the base or parent class) and to gain its interface.
Polymorphism is the feature that two classes can have methods that are named the same and have essentially the same purpose, but different implementations.
The keywords, Overridable, Overrides, MustInherit, and MustOverride allow derived classes to customize inherited properties and methods.