Chapter 5. Interfaces
When defining a class, you have to provide the implementation for all its methods and properties. However, there are times when you do not want to provide the actual implementation of how a class might work. Rather, you want to describe the functionalities of the class. This set of descriptions is like a contract, dictating what the class will do, the types of parameters needed, and the type of return results. In object-oriented programming, this contract is known as an interface.
An interface defines a class and its members without providing any implementation. When using interfaces in programming, generally three parties are involved:
Interface definition — The interface defines the composition of a class, such as methods, properties, and so on. However, the interface does not provide any implementation for any of these members.
Implementing class — The class that implements a particular interface provides the implementation for all the members defined in that interface.
Clients — Objects that instantiate from the implementing classes are known as the client. The client invokes the methods defined in the interface, whose implementation is provided by the implementing class.
Get C# 2008 Programmer's Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.