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


VbIiByDelegation?:

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.

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

VbIiByCallingChildren:
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.

VbStandardModuleAsBaseClass?
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.)

VisualBasicDotNet
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

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=Ot4zL6ZFEHA.2956%40tk2msftngp13.phx.gbl&rnum=1&prev=/groups%3Fsafe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-8%26as_ugroup%3Dmicrosoft.public.vb.general.discussion%26as_usubject%3DImplements%26as_drrb%3Db%26as_mind%3D12%26as_minm%3D3%26as_miny%3D2004%26as_maxd%3D31%26as_maxm%3D3%26as_maxy%3D2004%26lr%3D%26hl%3Den

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 )


CategoryVbClassic


EditText of this page (last edited January 31, 2009) or FindPage with title or text search