Multiple Interface Inheritance
Like a class, you can derive an interface from another interface. Unlike a class, you can derive an interface from
multiple interfaces. A derived interface inherits all the members from the base interface(s).
public interface IDrawable
{
void Draw(); // <-- Note possible name clash here!
}
public interface IPrintable
{
void Print();
void Draw(); // <-- Note possible name clash here!
}
// Multiple interface inheritance. OK!
public interface IShape : IDrawable, IPrintable
{
int GetNumberOfSides();
}
A class supporting the derived interface must implement all members of the derived interface, including the
inherited ones.
public class Square : IShape
{
// Using explicit implementation to handle member name clash.
void IPrintable.Draw()
{ // Draw to printer ...
}
void IDrawable.Draw()
{ // Draw to screen ...
}
public void Print()
{ // Print ...
}
public int GetNumberOfSides()
{ return 4; }
}
Interfaces and Polymorphism
Table of Contents
C# Tutorial | C#.NET Tutorial | Interfaces Tutorial
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
|
Courseware
Training Resources
Tutorials
Services