Vb Classic Implementation Inheritance

How can you get Implementation-InheritanceInVbClassic, when the VbClassic language does not directly support it? The following are a few ideas on how to do it.

(Inheritance is an issue for some refactorings you'd want to do if you were RefactoringInVbClassic.)

2004 Note: This page is relevant to VbClassic only, as VbDotNet is a different animal all together

Child class holds an instance of the base class as a private member variable, and forwards calls to it. Child class must implement the base class interface and all its methods, even if they do nothing but delegate.

Use an external tool to modify the source code, copying and generating code where needed.

Base class calls child classes to see if they implement the method. Relies on run-time method lookup.

VbIiByStatusFlag?: (...or VbIiSimulationWithTypeCode??)
Base class checks internal status flag to determine which child class it should behave as. MartinFowler mentions this simple approach in AnalysisPatterns.

All the methods you'd normally put in a base class, put them instead in a StandardModule?. Child classes "inherit" these methods by calling (delegating to) them. (It's tedious and repetitive, but I've done it. Works well with code generation.)

Upgrade to VisualBasic version 7.

Is VbIiByStatusFlag? a strategy of "implementing a hierarchy of classes" by collapsing all methods up into the base class and using switch/case statements, based on a type code, to select the appropriate behavior for each method? (...just asking; I don't happen to have that book.) -- JeffGrigg

Of course, with each of these artifact, you must abandon the OpenClosedPrinciple. VB is ObjectTinted?, not ObjectOriented.

Discussions in Newsgroups regarding use of Implements


The above has dialog as early as 1999, and as recent as 2004. A good Microsoft article cited within is located at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvb600/html/ifacebased.asp The article is taken from book Programming Distributed Applications with COM & Microsoft Visual Basic (ISBN 1-57231-961-5 )


View edit of January 31, 2009 or FindPage with title or text search