Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

multiple inheritance

Former Member
0 Likes
1,353

hi all

can anybody tell me why multiple inheritance is not supported in ABAP? is it design aspect or any logic involved?

regards

mainak

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
611

I can't give you a reason why multiple inheritance is not supported, but you can simulate multiple inheritance in ABAP objects using interfaces.

Regards,

Rich Heilman

Read only

0 Likes
611

Can u pls give me one example of using INTERFACE instead of multiple inheritance...

Thanks n Regards

Rohit

Read only

0 Likes
611

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>

Read only

Former Member
0 Likes
611

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