Polymorphism

Polymorphism is not the ability for a cockatoo to magically change into a rabbit; it is in fact the ability for different object types to implement the same method, thereby allowing you to write VBA code without concerning yourself about what type of object you're using at the time. Another way of looking at it is that objects can be more than one type of thing.

There are two types of polymorphism: ad-hoc polymorphism (called overloading in Visual Basic .NET), and parametric polymorphism.

Parametric polymorphism is not implemented in Access 2003, and so will be ignored in this book.

Ad-hoc polymorphism provides the ability to use the same calling syntax for objects of different types. For example, suppose we have a bikes class and a cars class, each having its own methods to implement its own unique properties and behaviors, but since both need their tires pumped up occasionally, they would both have a pump_tires method. The actual code to implement this behavior would perhaps differ, but as long as their interface remained the same, our VBA code could simply call the pump_tires method for both, and be confident that each class knows how to pump up its own tires.

It's true that VBA doesn't demonstrate some of the characteristics of a true object-oriented language like C#, but it doesn't pretend to. Applications where you would need polymorphism or inheritance would not be written in VBA, so VBA doesn't need to implement them.

0 0

Post a comment