Well, for starters, the classes don't have to be nested - classes A and B
can be defined outside Main if you like.
Next, Class Main can inherit from one of them - for this example, let's say
it's A. That takes care of one issue.
Before proceeding, you'll need to create an Interface for class B (let's
call it IClassB). This interface lists all the public members of B.
Now, you can implement IClassB in your class Main. For the implementation,
you'll need to create a private instance of B, and call that instance's
members from your implementation of IClassB in Main.
Public Interface IClassB
Sub DoSomething ( )
End Interface
Public Class B
Implements IClassB
Public Sub DoStuff ( ) Implements IClassB.DoStuff
' base implementation code goes here
End Sub
End Interface
Public Class Main
Inherits A
Implements IClassB
Private privateB As New B
Public Sub DoStuff( ) Implements IClassB.DoStuff
privateB.DoStuff( ) ' <--- delegation to class B instance here
End Sub
End Class
Again, there are nuances that prevent this from being a "true" substitution
of inheritance. For instance, Main has no way of dealing with B's Protected
members in this sample (unless you use Reflection and have enough access
permissions to invoke non-public members). But this should serve as a simple
example of the technique.
-Rob Teixeira [MVP]