- COM: No Implementation Inheritance
- The Next Stage: .NET and Visual Basic .NET
- Problems and Solutions
- Conclusion
The Next Stage: .NET and Visual Basic .NET
Back to the story. After VB6 came .NET and Visual Basic .NET. I thought implementation inheritance was bad and that I should stay away from it and continue to separate the implementation from the interface. It's definitely alright to continue to separate interface from implementation, and Microsoft has evolved the support for user-defined interfaces. For example, as a VB developer you don't have to write the interfaces in IDL any longer. You can also mark a method in a class so as to both implement an interface and have a natural name.
Let's look at a code snippet. First, I've created an interface called IMyInterface:
Public Interface IMyInterface Sub DoSomeStuff() End Interface
To implement IMyInterface, I wrote the Implementor class below:
Public Class Implementor Implements IMyInterface Public Sub DoIt() Implements IMyInterface.DoSomeStuff '... End Sub End Class
Note that method DoIt() is both the implementation of the interface method and a method that can be used on its own. In the code below, you can see two variants of how the Implementor class can be used, first via the interface and then directly as the class:
Dim x As IMyInterface x = New Implementor() x.DoSomeStuff() Dim y As New Implementor() y.DoIt()