Interfaces and Use of Interfaces in C# Programming


Interface are same as classes but they have no implementation. They have to be implemented in a class. It is like a skeleton of a class in which all the members (Functions) of class are given but no implementation is done inside and interface i.e. No body of functions. You can define interface by using the keyword interface and interface cannot contain fields. They are public by default. 

Interfaces can inherit from one or more base interfaces. You have to declare the corresponding member on a class as public, non static and with same signature and name to implement the interface member. It can not inherit a class and its instance can not be made directly as it is abstract (no implementation).

Uses of Interfaces:

There are two BIG reasons to use implementation other wise we can implement direct in a class. Following are the Uses of Interfaces:

  • Standardization
  • Distributed Computing
It means that we use interface because if we want to give the details of the classes we used in a program, then we will give him the interface so that he will know only the methods used, not the coding of entire Class. Only Skeleton of Class will be shown on client side by using interfaces.

We have discussed implementation of interfaces in Explicit Interface and Implicit Interface in OOP

Hit Like Button if you understood, It helps a lot to keep us Motivated.


Post a Comment