Object OrientationAn Introduction
The world of object orientation is exciting, but it requires a new way of thinking about things. Access Office 2003 is object-based, rather than object-oriented. So, what exactly is the difference? The definitions of the following terms should help you differentiate between these two concepts:
- Class
A template for an object - Object
An instance of a class - Instantiation
The process of creating an object based on a class - Polymorphism
The state of being multifaced; using the same method and property names with different objects, the properties and methods of which are implemented differently for different objects - Subclassing
Building one class based on another - Inheritance
In object-oriented programming, the ability of newly created subclasses to take on the behavior of their parent classes
VBA, and therefore Access, supports the creation of custom classes and the instantiation of objects based on those classes. Polymorphism can also be simulated by using the same property and method names within different classes. VBA does not fully support subclassing and inheritance. With the exception of a keyword called Implements, classes cannot be based on other classes and, therefore, cannot elicit the behavior of other classes. True polymorphism can exist only when child classes inherit the properties and methods of their parents. The Implements keyword gets you close, but does not fully exhibit the behavior of polymorphism.To make sure that you understand the terms, let's use an analogy. Imagine that you are going to bake some cookies. The cookie cutter is the class, the template for a cookie object. When you use the cookie cutter to create an actual cookie, you instantiate the cookie class to create a cookie object. The cookie has some properties, such as a powdered sugar property, and some methods, such as the bake method. A ham class is a template for a ham object. The ham class also has a bake method. The "code" behind the bake method of the cookie object and the bake method of the ham object is different. This is polymorphism (being multifaced) in action. If VBA were fully object-oriented, the cookie class and the ham class would have been derived from the same parent. When you would change the code of the parent, the changes would automatically be seen in the children. Now that you are familiar with some object-oriented terms and concepts, take a look at how custom classes work in VBA.