You can think of an interface as a special case of an abstract class. An interface defines properties and methods that a class must implement in order to be considered a member of a group identified with the interface name.
For example, in C#, the language that supports interfaces, we can create the IAlien
interface that specifies the following elements:
The
NumberOfEyes
propertyThe parameterless method named
Appear
The parameterless method named
Disappear
Once we define an interface, we can use them to specify the required type for an argument. This way, instead of using classes as types, we can use interfaces as types and an instance of any class that implements the specific interface as the argument. For example, if we use IAlien
as the required type for an argument, we can pass an instance of any class that implements IAlien
as the argument.
However, you must take into account some limitations of all the interfaces compared with classes. Interfaces...