Interface Example Multiple Inheritance
Interface Example Multiple Inheritance
"-------------------------------------------------------
" Interface: Printable
"-------------------------------------------------------
INTERFACE if_printable.
CONSTANTS:
c_format TYPE string VALUE 'PDF'.
METHODS:
print,
get_document_type RETURNING VALUE(rv_doc_type) TYPE string.
CLASS-METHODS:
show_print_info.
ENDINTERFACE.
"-------------------------------------------------------
" Interface: Exportable (another capability)
"-------------------------------------------------------
INTERFACE if_exportable.
METHODS:
export_as_json,
export_as_xml.
ENDINTERFACE.
"-------------------------------------------------------
" Class: Invoice - Implements 2 interfaces
"-------------------------------------------------------
CLASS lcl_invoice DEFINITION.
PUBLIC SECTION.
INTERFACES: if_printable, if_exportable.
METHODS: get_total_amount,
display_invoice_id.
ENDCLASS.
METHOD if_printable~print.
WRITE: / 'Printing Invoice as:', if_printable=>c_format.
ENDMETHOD.
METHOD if_printable~get_document_type.
rv_doc_type = 'INVOICE'.
ENDMETHOD.
METHOD if_exportable~export_as_json.
WRITE: / 'Invoice exported in JSON format'.
ENDMETHOD.
METHOD if_exportable~export_as_xml.
WRITE: / 'Invoice exported in XML format'.
ENDMETHOD.
METHOD get_total_amount.
WRITE: / 'Total Invoice Amount: 2500.00'.
ENDMETHOD.
METHOD display_invoice_id.
WRITE: / 'Invoice ID: INV1001'.
ENDMETHOD.
METHOD if_printable~show_print_info.
WRITE: / 'This document will be printed in', if_printable=>c_format, 'format.'.
ENDMETHOD.
ENDCLASS.
"-------------------------------------------------------
" Class: Delivery Note - Implements only Printable
"-------------------------------------------------------
CLASS lcl_delivery_note DEFINITION.
PUBLIC SECTION.
INTERFACES: if_printable.
METHODS: delivery_partner.
ENDCLASS.
METHOD if_printable~print.
WRITE: / 'Printing Delivery Note as:', if_printable=>c_format.
ENDMETHOD.
METHOD if_printable~get_document_type.
rv_doc_type = 'DELIVERY NOTE'.
ENDMETHOD.
METHOD delivery_partner.
WRITE: / 'Delivered via: Speed Logistics'.
ENDMETHOD.
METHOD if_printable~show_print_info.
WRITE: / 'This document will be printed in', if_printable=>c_format, 'format.'.
ENDMETHOD.
ENDCLASS.
"-------------------------------------------------------
" Program Execution
"-------------------------------------------------------
START-OF-SELECTION.
lo_exportable->export_as_json( ).
lo_exportable->export_as_xml( ).
ULINE.
ULINE.
ULINE.
lo_delivery_interface->if_printable~print( ).
WRITE: / 'Doc Type:', lo_delivery_interface->if_printable~get_document_type( ).