Vb.net: multiple inheritance in the interface

I have a problem with multiple inheritance in VB.net:

As far as I know, VB.net does not support multiple inheritance at all, but you can achieve some sort of multiple inheritance by working with interfaces (using "Implements" instead of "Inherit"):

Public Class ClassName Implements BaseInterface1, BaseInterface2 End Class 

This works fine for classes, but Id loves to have an interface inheriting some basic interfaces. Something like that:

 Public Interface InterfaceName Implements BaseInterface1, BaseInterface2 End Interface 

But the keyword "Implements" is not allowed for interfaces (which, of course, makes sense). I tried using some abstract class that I know from Java:

 Public MustInherit Class InterfaceName Implements BaseInterface1, BaseInterface2 End Class 

But now I need to implement certain methods from BaseInterface1 and BaseInterface2 in the InterfaceName class. But since InterfaceName must also be an interface, I do not want to implement these methods in this class.

In C #, you can do this quite simply:

 public interface InterfaceName: BaseInterface1, BaseInterface2 {} 

Do you know that I can do something like this in VB.net?

+8
interface multiple-inheritance
source share
4 answers

Like Java, VB.NET interfaces β€œextend” other interfaces. This means that they "inherit" their functionality. They do not realize it.

 Public Interface InterfaceName Inherits BaseInterface1, BaseInterface2 End Interface 
+21
source share

Try

 Public Interface InterfaceName Inherits BaseInterface1 Inherits BaseInterface2 End Interface 
+8
source share

The workaround is to pass an abstract class (mustinherit) to define each element in an interface that it does not want to implement using mustoverride. Try to predefine each of them in a general sense, if possible, and make it excessive.

0
source share

I would be careful when inheriting interfaces.

While it works, I found that if you bind a BindingList (Of InterfaceName) to a BindingSource and a BindingSource to a DataGridView, then the properties in Interface1 and Interface2 are not visible to the Visual Studio DataGridView designer to highlight as DataGridView columns.

0
source share

All Articles