The usual way to do this in VBA is to have A contain an instance of B, and also have an implementation interface B, and then delegate calls to B-interface A to internal B.
This is old stuff, but see the Visual Studio 6.0 Programmer's Guide:
http://msdn.microsoft.com/en-us/library/aa716285(VS.60).aspx
There is a chapter called “Much (Inter) entity code reuse” that describes this convention:
http://msdn.microsoft.com/en-us/library/aa240846(v=VS.60).aspx
The way MS describes this:
In addition to implementing abstract interfaces, you can reuse your implementation code for an interface of a regular class, and then selectively delegating the hidden instance of the class.
This means that implementation inheritance requires many explicit delegation methods. There's even the head of the subtitle: "Isn't that tiring?" Another reason OOP in VBA is PITA (TM) ...
CHANGE THAT DOES NOT TAKE A COMMENT:
To answer the question that you asked in your comment, well, A is B. When you create an implementation interface B, you basically say that you can process an instance of A as if it were actually type B. In VBA, how do you do this by declaring a variable of type B and then setting it to instance A. VBA will know what to do when you name it as B:
Dim usedAsB as B Dim anA as A Set anA = New A Set usedAsB = anA 'fine since A implements B usedAsB.something() 'will call B_something() defined in class A
As you can see in the debug window, I don’t understand why it looks like this. And as for the forced delegation, I'm not sure what you mean. VBA automatically sends calls to interface B to the correct methods in class A. If you mean automatically generating code to inherit the implementation of B in the manner described above, I do not know anything similar for VBA. I think various “professional” versions of VB6 can do this, but I never used VB6, so I don’t know.
jtolle Sep 08 '10 at 20:01 2010-09-08 20:01
source share