SAP ABAP Polymorphism - SAP ABAP

What is polymorphismin sap abap?What is the procedure?

The term poly refers ‘many’ and morphism indicates ‘changes’ means ‘many changes’. From an object-oriented point of view, polymorphism works in relation with inheritance. That is, polymorphism helps in exhibiting the values or different behaviour to the sub class which has been inherited from the parent class. So, when a method is defined in a parent class, each subclass has its own method in its implementation. This differs each subclass without the knowledge of differences of the subclasses to the parent class. This means polymorphism relates to the method which is executed in a parent class is not same and they change according to their subclasses depending upon the type of the object.

The following program contains an abstract class of 'class_prgm', and 2 sub classes (class_procedural and class_OO), and a test driver class 'class_type_approach'. In this implementation, the class method 'start' allow us to display the type of program and its approach. Then If you at at the signature of method 'start', you will find that it inherits an importing parameter of type class_prgm. However, in the Start-Of-Selection event, this method has been called at run-time with objects of type class_procedural and class_OO.


The above code produces the following output –

ABAP run-time environment performs an implicit narrowing cast when the importing parameter class1_prgm is executed. This feature helps the 'start' method to be implemented generically. The ABAP run time environment helps to bind a method call with the implemented defined object by the object reference variable. For instance, the importing parameter 'class1_prgm' for method 'start' in the 'class_type_approach' class refers to an abstract type that never represents on its own.

Whenever the method is called with a concrete sub class implementation such as class_procedural or class_OO, the dynamic type called as class1_prgm reference parameter is bounded to one of these concrete types. Therefore, the subclasses class-procedural or class_OO inherits data from the parent class that is class1_prgm which is dynamic type. So when the method is declared in the parent class of pgrm type, implementations are provided in class procedural and class_OO approach rather than the undefined abstract implementations provided in class 'class_prgm'.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status