* die Klasse, deren Objekte geclont werden sollen, muss von CL_OS_STATE
* ableiten, damit das Interface IF_OS_CLONE implementiert wird
CLASS lcl_clone_test DEFINITION INHERITING FROM cl_os_state.
PUBLIC SECTION.
* ALIAS für die Implementierung von cl_os_state=>if_os_clone~clone( )
* ruft SYSTEM-CALL OBJMGR CLONE me TO result.
ALIASES: clone FOR if_os_clone~clone.
METHODS:
constructor
IMPORTING i_text TYPE string.
METHODS:
get_text
RETURNING VALUE(rv_text) TYPE string.
PRIVATE SECTION.
DATA:
gv_text TYPE string.
ENDCLASS.
CLASS lcl_clone_test IMPLEMENTATION.
METHOD constructor.
* Konstruktor der Basisklasse CL_OS_STATE rufen
super->constructor( ).
gv_text = i_text.
ENDMETHOD.
METHOD get_text.
rv_text = gv_text.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(o_src) = NEW lcl_clone_test( 'SRC' ).
WRITE: / o_src->get_text( ).
* Objekt O_SRC clonen, Rückgabe von REF TO object nach LCL_CLONE_TEST explizit casten
* es wird ein neues, zu O_SRC identisches, Objekt erzeugt
DATA(o_clone) = CAST lcl_clone_test( o_src->clone( ) ).
WRITE: / o_clone->get_text( ).