Information Technology Reference
In-Depth Information
Interfaces Can Inherit Interfaces
You saw earlier that interface implementations can be inherited from base classes. But an
interface itself can inherit from one or more other interfaces.
To specify that an interface should inherit from other interfaces, place the names of the
base interfaces in a comma-separated list after a colon, following the interface name in
the interface declaration, as follows:
Colon
Base interface list
↓
↓
interface IDataIO : IDataRetrieve, IDataStore, IDataRestore
{ ...
Unlike a class, which can only have a single class name in its base class list, an interface
can have any number of interfaces in its base interface list.
- The interfaces in the list can themselves have inherited interfaces.
- The resulting interface contains all the members it declares, as well as all those of its
base interfaces.
The code in Figure 17-10 shows the declaration of three interfaces. Interface
IDataIO
is
derived from the first two. The figure on the right shows
IDataIO
encompassing the other two
interfaces.
Figure 17-10.
Class with interface inheriting multiple interfaces