What is Polymorphism in Object Oriented Programming model ?It is a concept by which the same method names will behave differently in different classes i.e each method will have its own implementation in different different classes but with the same name.
Interface is one of the concept in Object Oriented ABAP to achieve Polymorphism.
What is an interface in Object Oriented ABAP ?
- Interfaces are independent structure which are used in a class to extend the functionality of a class.
- Interfaces contains methods without any implementation. Where as a class contains methods with implementation.
- We need to define an interface with the required method names in SE24 TCODE.
- The interfaces can be used by no of classes to extend the functionality of the class.
- To implement an interface in a class just give the name of interface under the 'Interfaces' tab.
- All the interface methods will be automatically copied to the classes in a particular class without effecting the other classes.
- The main use of interfaces is re-usability and maintain standard project framework.
In the above diagram, application is business application, Class A, Class B, Class C, Class D and Class E are independent classes, all these classes are using one Interface called Interface( in diagram).
In all the classes,the methods names are same but the implementation will be different from one class to another class thereby achieving the concept called POLYMORPHISM. Polymorphism is implemented in the from of interface.