Multiple Interface Inheritance

Visual Basic .NET does not support multiple class inheritance, but it does support multiple interface inheritance. If a class inherits from multiple interfaces, the class must implement all the members defined by all the interfaces the class inherits from.

When a class will implement multiple interfaces, indicate each interface in a comma-delimited list in the Implements statement.

 Implements IDrawable2, IFoo 

If two interfaces declare members with identical signatures, you will need to resolve the implementation in the implementing class. For example, suppose IDrawable2 and IFoo define identical Draw methods . You could indicate that a single Draw method provides the implementation for both interfaces.

 Public Sub Draw(ByVal G As Graphics) Implements IDrawable2.Draw, IFoo.Draw   ' Code here End Sub 

If two or more interfaces inherit from a common base interface and a class implements both derived interfaces, the duplicate members inherited from the common base are treated as if they need to be implemented only one time. Here is a brief example demonstrating how to resolve the conflict.

 Public Interface IA   Sub Foo() End Interface Public Interface IB   Inherits IA End Interface Public Interface IC   Inherits IA   Sub Foo2() End Interface Public Class AClass   Implements IB, IC   Public Sub Foo() Implements IA.Foo   End Sub   Public Sub Foo2() Implements IC.Foo2   End Sub End Class 

Interfaces IB and IC inherit from interface IA . Interface IC introduces Foo2 . If a class implements both IB and IC , the consumer would need to implement only IA.Foo and IC.Foo2 . The consumer would not and cannot implement IB.Foo and IC.Foo . The conflict is resolved by implementing the conflicting method as it is defined in the base class.



Visual Basic. NET Power Coding
Visual Basic(R) .NET Power Coding
ISBN: 0672324075
EAN: 2147483647
Year: 2005
Pages: 215
Authors: Paul Kimmel

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net