Implementing an Interface on Base class' signatures

Is it possible in vb.net to implement an interface using a base class' signatures I come from C# so this is something that c# can handle because it implements interfaces on the logical assumption that the signature and the signature name are the same so it is an implementation of the interface signature. Also, I do not have access to the base class so this must be done through a derived class.

For example I have an interface

Public Interface

Property Data()

End Interface

Public MustInherit Class BaseClass

Public Property Data()

End Class

So when I try to derive from this class and implement the interface the compiler blows up saying I haven't implemented it yet or it creates Data1() that implements the interface.



Answer this question

Implementing an Interface on Base class' signatures

  • think twice

    Visual Basic forces you to explicitly tell that you are implementing an interface method. It also allows you to decouple the name of the method/property used for the implementatino from the name of the method/property in the interface. Below is a suggestion on how you can do this:

    Public Class Derived
    Inherits BaseClass
    Implements [Interface]

    Private Property IFoo_Data Implements [Interface].Data
    Get
    return MyBase.Data
    End Get
    Set value
    MyBase.Data = value
    End Set
    End Property
    End Class

    Please note that I don't have a VB compiler on my machine right now, so there may be a typo or two :)

    Best regards,
    Johan Stenberg



  • Implementing an Interface on Base class' signatures