*&---------------------------------------------------------------------*
*& Report YSAP_OOABAP_POLYMORPHISM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ysap_ooabap_polymorphism.
*----------------------------------------------------------------------*
* INTERFACE interface1
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE interface1.
METHODS method1.
ENDINTERFACE. "interface1
*----------------------------------------------------------------------*
* CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION.
PUBLIC SECTION.
INTERFACES interface1.
ENDCLASS. "class1 DEFINITION
*----------------------------------------------------------------------*
* CLASS class1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
METHOD interface1~method1.
WRITE:/ 'method1 from claas1' COLOR 6.
ENDMETHOD. "interface1~method1
ENDCLASS. "class1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION.
PUBLIC SECTION.
INTERFACES interface1.
ENDCLASS. "class2 DEFINITION
*----------------------------------------------------------------------*
* CLASS class2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 IMPLEMENTATION.
METHOD interface1~method1.
WRITE:/ 'method1 from class2' COLOR 7.
ENDMETHOD. "interface1~method1
ENDCLASS. "class2 IMPLEMENTATION
START-OF-SELECTION.
DATA: object1 TYPE REF TO class1,
object2 TYPE REF TO class2,
object TYPE REF TO interface1.
CREATE OBJECT: object1, object2.
object = object1.
CALL METHOD: object->method1.
object = object2.
CALL METHOD object->method1.
*& Report YSAP_OOABAP_POLYMORPHISM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ysap_ooabap_polymorphism.
*----------------------------------------------------------------------*
* INTERFACE interface1
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
INTERFACE interface1.
METHODS method1.
ENDINTERFACE. "interface1
*----------------------------------------------------------------------*
* CLASS class1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 DEFINITION.
PUBLIC SECTION.
INTERFACES interface1.
ENDCLASS. "class1 DEFINITION
*----------------------------------------------------------------------*
* CLASS class1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class1 IMPLEMENTATION.
METHOD interface1~method1.
WRITE:/ 'method1 from claas1' COLOR 6.
ENDMETHOD. "interface1~method1
ENDCLASS. "class1 IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS class2 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 DEFINITION.
PUBLIC SECTION.
INTERFACES interface1.
ENDCLASS. "class2 DEFINITION
*----------------------------------------------------------------------*
* CLASS class2 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class2 IMPLEMENTATION.
METHOD interface1~method1.
WRITE:/ 'method1 from class2' COLOR 7.
ENDMETHOD. "interface1~method1
ENDCLASS. "class2 IMPLEMENTATION
START-OF-SELECTION.
DATA: object1 TYPE REF TO class1,
object2 TYPE REF TO class2,
object TYPE REF TO interface1.
CREATE OBJECT: object1, object2.
object = object1.
CALL METHOD: object->method1.
object = object2.
CALL METHOD object->method1.
Output:
No comments:
Post a Comment