‎2005 Mar 03 2:09 PM
hi all
can anybody tell me why multiple inheritance is not supported in ABAP? is it design aspect or any logic involved?
regards
mainak
‎2005 Mar 03 2:16 PM
‎2007 Oct 04 1:39 PM
Can u pls give me one example of using INTERFACE instead of multiple inheritance...
Thanks n Regards
Rohit
‎2007 Oct 04 2:47 PM
In ABAP Objects, the same components (attributes, methods, constants, types, alias names) can be
defined in an interface in largely the same way as in classes. However, interfaces do not have component
visibility sections.
Interfaces are implemented in classes.
The interface name is listed in the definition part of the class. Interfaces can only be implemented publicly
and are therefore always in the PUBLIC SECTION (this is only valid as of Release 4.6). If you do not do
this, you risk multiple implementations, if a superclass and a subclass both implement the same interface
privately.
The operations defined in the interface are implemented as methods of a class. A check is carried out to
ensure that all the methods defined in the interfaces are actually present in the implementation part of the
class
<b>Declaration of an interface</b>
INTERFACE lif_document.
DATA: author TYPE REF TO lcl_author.
METHODS: print,
display.
ENDINTERFACE.
CLASS lcl_text_document DEFINITION.
PUBLIC SECTION.
INTERFACES lif_document. <b> " Defining within a class.</b>
METHODS: display.
ENDCLASS.
CLASS lcl_img_document DEFINITION.
PUBLIC SECTION.
INTERFACES lif_document. <b> " Defining within a class.</b>
METHODS: display.
ENDCLASS.
<b>*Interfaces are implemented in classes</b>
CLASS lcl_text_document IMPLEMENTATION.
METHOD lif_document~print.
<b>*Your specific code here....</b>
ENDMETHOD.
METHOD lif_document~display.
<b>*Your specific code here....</b>
ENDMETHOD.
METHOD display.
ENDMETHOD.
ENDCLASS.
CLASS lcl_img_document IMPLEMENTATION.
METHOD lif_document~print.
<b>*Your specific code here....</b>
ENDMETHOD.
METHOD lif_document~display.
<b>*Your specific code here....</b>
ENDMETHOD.
METHOD display.
ENDMETHOD.
ENDCLASS.
*Creating an object of that class.
DATA: text_doc TYPE REF TO lcl_text_document.
<b>*Calling methods</b>
CREATE OBJECT text_doc.
CALL METHOD text_doc->lif_document~print.
CALL METHOD text_doc->lif_document~display.
CALL METHOD text_doc->display.
<b>The interface resolution operator enables you to access interface components using an object reference
belonging to the class implementing the interface in exactly the same way as the method definition in the
implementation part of the class.
This allows you to differentiate between components defined in the interface and components of the same
name that are defined in the class itself. This is caused by the shared namespace.
</b>
<b>Hope this is helpful, Do reward.</b>
‎2005 Mar 04 1:51 AM
Probably for 2 reasons:
1. the complexity of implementing the feature
2. the limited use of the feature
As Rich mentioned you can use Interfaces to simulate multiple inheritance. A somewhat similar feature is called Friends.
The different relationships possible are describe here:
http://help.sap.com/saphelp_470/helpdata/en/ca/c035b7a6c611d1b4790000e8a52bed/frameset.htm