|
Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
In C# a class can be derived from only one base class. That is, the following declaration is not allowed:
class A {}
class B {}
class C : A, B // Wrong;
{
}
Nevertheless, it is possible for a class to extend a base class
and to implement one or more interfaces:
class A {}
interface D {}
interface E {}
class C : A, D, E
{
}
The derived class C inherits the members of A
and it implements all the methods defined
in the interfaces D and E.
It is possible to use derivation in the definition of interfaces. And in C# it is possible for an interface to extend more than one base interface:
interface E {}
interface F {}
interface D : E, F
{
}
In this case, the derived interface D comprises
all the methods inherited from E and F
as well as any new methods declared in the body of D.