This program uses three objects. It invokes the Value property let procedure for each object many times so you can see which is fastest.
The first object is declared to be of type Object and it is set to a new SpecificClass object that provides the property procedure directly.
The second object is a declared to be of type ImplementorClass. This class uses the Implements keyword to indicate that it implements the Value property procedures defined by the ImplementedClass class.
The third object is a declared to be of type SpecificClass. This class provides the property procedure directly.
You will find that the generic Object takes 10 to 12 times as long as the others.
Of course using specific objects is also fast. The point is that using Implements you can manage several different classes that all implement the same features quickly without using generic Objects. My book Ready-to-Run Visual Basic Algorithms has a chapter on object-oriented algorithms in Visual Basic that covers this and some other interesting stuff.
|