2011 Jul 07 12:07 PM
I have an interface ZIF_TEST and define a class ZCL_TEST and implement its method TEST.
I created a class ZCL_DO and implement the interface ZIF_TEST.
I wanna ZCL_DO could use the method TEST implemented in ZCL_TEST but how?
I see the SAP standard class can do this...
Edited by: kkktank on Jul 7, 2011 1:08 PM
I have an interface ZIF_TEST and define a class ZCL_TEST and implement its method TEST.
I created a class ZCL_DO and implement the interface ZIF_TEST.
I wanna ZCL_DO could use the method TEST implemented in ZCL_TEST but how?
I see the SAP standard class can do this...
Edited by: kkktank on Jul 7, 2011 1:08 PM
2011 Jul 07 1:10 PM
Hi.,
Make ZCL_DO as a sub class of ZCL_TEST so that you can use its methods..
Thanks & Regards,
Kiran
2011 Jul 09 6:12 PM
Hi kk,
it requires that TEST is a public method. If it is static method, ZCL_DO=>TEST calls the method, if it is instance method, lo_DO->TEST calls the method.
What is your code (formatted as code)?
Regards,
Clemens
2011 Jul 11 7:08 AM
Hello,
you can also call it, if the method is private or protected using friendship relationship. If class ZCL_DO will be a friend of ZCL_TEST, it may use it's methods as they were public.
The problem is, that you cannot restrict the friendship to only one method, but if this doesn't contradict your requirements, there is your solution.
CLASS zcl_do DEFINITION.
....
ENDCLASS.
CLASS zcl_test DEFINITION FRIENDS zcl_do.
....
ENDCLASS.
CLASS zcl_do IMPLEMENTATION.
METHOD do_someting.
DATA lo_ref TYPE REF TO zcl_test.
CREATE OBEJCT lo_ref.
CALL METHOD lo_ref->zif_test~test.
ENDMETHOD.
ENDCLASS.
2011 Jul 13 2:21 PM
use upcasting same logic as with classes. but you will get implementation specific to child class while u are only interested in the ZCL_TEST class, okay then make the other class a child class of this Test class nad then do not redefine so that when u call instance of the child class ->interface~method u will executr the implementation inside the TEST class.
2011 Jul 14 4:42 AM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |