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

Why interface method not inheriting from into class ?

Former Member
0 Likes
726

Hi,

I created zinter interface in that method zmethod is there. I inherited this interface to zinterface1 and zinterface2. Again I defined the method zmethod1 in both interfaces zinterface1 and zinterface2. Now If I am inheriting the 2 interfaces zinterface1 and 2, in the class only zinterface1~method1 and zinterface2~method1 are displaying. Why zinter interface method zmethod is not displaying ?

the hierarchy is like below.

zinter - method

zinterface1 inherited from zinter having method zmethod1

zinterface2 inherited from zinter having method zmethod1.

zclass inherited from zinterface1 and zinterface2 having method zinterface~method1 and zinterface~method1.

Thank you.

3 REPLIES 3
Read only

naimesh_patel
Active Contributor
0 Likes
693

What you are trying in implementing the Composite Interface. In an interface, a component will only appear once even though it is defined multiple times. E.g. in you example, ZINTER is defined more than once in the Class definition as part of ZINT1 and ZINT2. You would be only able to create a Single implementation of ZINTER~ZMETHOD.

sk yakub wrote:

Why zinter interface method zmethod is not displaying ?

I guess you referring to the Tree hierarchy display. Since you have declared your concrete class with INTERFACEs: zint1, zint2. only they are visible as in Class hierarchy. If you drill down the interface hierarchy of ZINT1, you would see the ZINTER.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
693

Hi Yakub,

I have tried this it is displaying zmethod of zinter interface.

Interface methods are always referred by the interface in which it is defined. It does not depend on the interface that is implementing that interface.

Suppose you have an interface name ZIF_SUPER, In this interface you have some method named add. Now if there are two more interfaces named ZIF_SUB1 & ZIF_SUB2 they both are implementing the interface ZIF_SUPER. Now both the interface will have method ZIF_SUPER~ADD.

Now suppose if you add one more method named MINUS to both the interface and then implement both the interface in One class suppose ZCL_INTERFACE_TEST, then in this class only three method named ZIF_SUPER~ADD , ZIF_SUB1~MINUS and ZIF_SUB2~MINUS will be available to you.

Regards

Ajeet Pratap Singh

Read only

Former Member
0 Likes
693

Hi,

To inherit methods of an interface into another, you just have to define its usage in the interface and not redefine the methods again.

e.g > interfaceA with method a_1 , interfaceB with method b_1, interfaceC with method c_1.

     Now i want methods of interfaceA to be inherited in interfaceB and interfaceC so what i do is define its usage.

INTERFACE interfaceB DEFINITION.

     INTERFACES interfaceA.

INTERFACEEND.

INTERFACE interfaceC DEFINITION.

     INTERFACES interfaceA.

INTERFACEEND.

Thats all and such type of interfaces including other interfaces are called Composite Interfaces.

Now in a class abc.

CLASS abc DEFINITION.

     INTERFACES interfaceB

ENDCLASS.

CLASS abc IMPLEMENTATION.

     METHOD interfaceA~a_1.

     ...

     ...

     ENDMETHOD.

     METHOD interfaceb~b_1.

     ...

     ...

     ENDMETHOD.

ENDCLASS.

Thank You.