ABAP Objects Advanced - Interfaces: IBM Global Business Services
ABAP Objects Advanced - Interfaces: IBM Global Business Services
ABAP Objects Advanced - Interfaces: IBM Global Business Services
Concept
Defining Interfaces
Implementing Interface in Classes
Compound Interfaces
Alias Names
Interface References
Polymorphism through interfaces
Interface and Inheritance
Interfaces : Concepts
CLASS C1 IMPLEMENTATION.
METHOD I1~m1. START-OF-SELECTION.
... DATA : oref TYPE REF TO c1
ENDMETHOD. CREATE OBJECT oref.
CALL METHOD : oref->I2~meth1.
METHOD : I2~m2.
CALL METHOD : oref->meth2 .
...
ENDMETHOD.
ENDCLASS.
Interfaces : Polymorphism
INTERFACE I1.
METHODS : M1 .
ENDINTERFACE. Interfaces allow to use different
CLASS C1 DEFINITION.
PUBLIC SECTION. classes in a uniform way using
INTERFACES : I1.
ENDCLASS.
interface references. Any no of class
CLASS C1 IMPLEMENTATION.
can implement the interface
METHOD I1~M1. differently.
.
ENDMETHOD.
ENDCLASS.
The identical interface reference
CLASS C2 DEFINITION. variable, statically typed to this
PUBLIC SECTION.
INTERFACES : I1. interface, operates on multiple
ENDCLASS.
CLASS C2 IMPLEMENTATION. objects that implement the interface.
METHOD I1~M1.
.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA : OREF1 TYPE REF TO C1 ,
OREF2 TYPE REF TO C2 ,
IREF TYPE REF TO I1 .
CREATE OBJECT : OREF1 ,
OREF2 .
IREF = OREF1.
CALL METHOD IREF->M1.
IREF = OREF2.
CALL METHOD IREF->M1.
Demonstration
Exercise 7:
In this exercise you will demonstrate Polymorphism through Interfaces.
Practice