Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The usual way to do this in VBA is to have A contain an instance of B as well as having A implement B's interface, and then delegate calls to the B interface of A to the internal B.</p> <p>This is old stuff, but see the Visual Studio 6.0 Programmer's Guide:</p> <p><a href="http://msdn.microsoft.com/en-us/library/aa716285(VS.60).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa716285(VS.60).aspx</a></p> <p>There is a chapter on "The Many (Inter)Faces of Code Reuse" that describes this convention:</p> <p><a href="http://msdn.microsoft.com/en-us/library/aa240846(v=VS.60).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa240846(v=VS.60).aspx</a></p> <p>The way MS describes it is: </p> <blockquote> <p>In addition to implementing abstract interfaces, you can reuse your code by implementing the interface of an ordinary class, and then selectively delegating to a hidden instance of the class.</p> </blockquote> <p>This means that implementation inheritance requires lots of explicit delegation methods. There's even a chapter subheading: "Doesn't This Get Tedious?". Yet another reason why OOP in VBA is a PITA (TM)...</p> <p>EDIT THAT WON'T FIT IN A COMMENT:</p> <p>To answer the question you posed in your comment, well, an A <em>is</em> a B. When you make A implement B's interface, you are essentially saying that you can treat an instance of A as if it is actually of type B. In VBA, the way you do that is by declaring a variable of type B, and then setting it to an instance of A. VBA will know what to do when you call it like a B:</p> <pre><code>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 </code></pre> <p>As far as what you see in the debug window, I don't why it appears that way. And as far as forced delegation, I'm not sure what you mean. VBA automatically dispatches calls to the B interface to the right methods in the A class. If you mean automatically generating the code to inherit B's implementation in the manner described above, there's nothing like that I know of for VBA. I think the various "professional" versions of VB6 could do that, but I've never used VB6 so I don't know.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload