MUltiple Inheritance in ABAP OOPS
MUltiple Inheritance in ABAP OOPS
MUltiple Inheritance in ABAP OOPS
interfaces.
ABAP objects doesnt support multiple inheritance using more than one class. In ABAP Objects, you can only define a class inheriting from only one class. If you try to define multiple super class while defining a class, compiler would prompt an error message.
Standard SAP has used multiple inheritance heavily in few development. E.g. Purchase Order Enjoy transaction. Like Purchase Order header class contain quite a lot interfaces within it to make it a full object. This way this object gets all the components from so many different interfaces. These interfaces could be also used to represent different part of different objects.
Demo UML
Here is the UML for this Demo
Code lines
Code to achieve multiple inheritance using interfaces. [abap_code slider="X" title=""] REPORT znp_multiple_inheritance. * INTERFACE lif_data. METHODS: get_data. ENDINTERFACE. lif_data * INTERFACE lif_output. METHODS: generate_output. ENDINTERFACE. lif_output * CLASS lcl_summary DEFINITION. PUBLIC SECTION. INTERFACES: lif_data, lif_output.
ENDCLASS. lcl_summary DEFINITION * CLASS lcl_summary IMPLEMENTATION. METHOD lif_data~get_data. WRITE: / Getting data for summary. ENDMETHOD. lif_data~get_Data METHOD lif_output~generate_output. WRITE: / Generating output. ENDMETHOD. lif_output~generate_output ENDCLASS. lcl_summary IMPLEMENTATION * CLASS lcl_detail_to_email DEFINITION. PUBLIC SECTION. INTERFACES: lif_data, lif_output. ENDCLASS. lcl_detail_to_email DEFINITION * CLASS lcl_detail_to_email IMPLEMENTATION. METHOD lif_data~get_data. WRITE: / Getting data for detail. ENDMETHOD. lif_data~get_data METHOD lif_output~generate_output. WRITE: / Sending an email. ENDMETHOD. lif_output~generate_output ENDCLASS. lcl_detail_to_email IMPLEMENTATION class lcl_main DEFINITION. PUBLIC SECTION. CLASS-METHODS: select_Data IMPORTING io_Data type ref to lif_data, write_Data IMPORTING io_output type ref to lif_output. ENDCLASS. * class lcl_main IMPLEMENTATION. method select_Data. io_data->get_Data( ). ENDMETHOD. method write_Data. io_output->generate_output( ). ENDMETHOD. ENDCLASS. * START-OF-SELECTION. datA: lo_report type ref to lcl_summary. create object lo_report.
lcl_main=>select_Data( lo_report ). lcl_main=>write_Data( lo_report ). data: lo_dtl_rep type ref to lcl_detail_to_email. create OBJECT lo_dtl_rep. lcl_main=>select_Data( lo_dtl_rep ). lcl_main=>write_Data( lo_dtl_rep ). [/abap_code]