An interface can be called a fully unimplemented class.
- Unlike abstract classes, all methods of an interface are by default abstract(having no function body), we do not explicitly have to mark them abstract
- All members are public and abstract by default
- Interfaces specify what a class must have and not how its methods should behave
- Interfaces can not have private members
- Interfaces support Abstraction and Polymorphism
- Here is an example of interfaces supporting polymorphism
Advantages of Interfaces
- Used to achieve loose coupling
- Used to achieve total abstraction
- Supports component based programming
- We can implement multiple inheritance and abstraction
- Interfaces also help in dependency injection
Comments
Post a Comment