Reputation: 143
I'm facing a problem regarding multiple inheritance in VB.net:
As far as I know VB.net does not support multiple inheritance in general but you can reach a kind of multiple inheritance by working with interfaces (using “Implements” instead of “Inherits”):
Public Class ClassName
Implements BaseInterface1, BaseInterface2
End Class
That works fine for classes but I’d like to have an interface inheriting some base interfaces. Something like that:
Public Interface InterfaceName
Implements BaseInterface1, BaseInterface2
End Interface
But the “Implements” keyword is not allowed for interfaces (what makes sense, of course). I tried to use a kind of abstract class which I know from Java:
Public MustInherit Class InterfaceName
Implements BaseInterface1, BaseInterface2
End Class
But now I need to implement the defined methods from BaseInterface1 and BaseInterface2 within the InterfaceName class. But as InterfaceName should be an interface, too, I don’t want to have to implement these methods within that class.
In C# you can do that quite easy:
public interface InterfaceName: BaseInterface1, BaseInterface2 {}
Do you know if I can do something similar in VB.net?
Upvotes: 14
Views: 18316
Reputation: 474
I would be careful when inheriting interfaces.
While it works, I have found that if you bind a BindingList(Of InterfaceName) to a BindingSource and the BindingSource to a DataGridView, then properties in Interface1 and Interface2 are not visible to the Visual Studio DataGridView designer for allocating as columns to the DataGridView.
Upvotes: -1
Reputation: 5107
A workaround is to have the abstract class (mustinherit) pass on the job of defining each item in the interface it does not want to implement with mustoverride. Try to predefine each one in a general sense if possible and make it overridable.
Upvotes: 0
Reputation: 22332
Similar to Java, in VB.NET interfaces "extend" other interfaces. That means they "inherit" their functionality. They do not implement it.
Public Interface InterfaceName
Inherits BaseInterface1, BaseInterface2
End Interface
Upvotes: 32
Reputation: 16673
Try
Public Interface InterfaceName
Inherits BaseInterface1
Inherits BaseInterface2
End Interface
Upvotes: 9