cancel
Showing results for 
Search instead for 
Did you mean: 

Modify Standard Abstract Classes.

Former Member
0 Kudos

I would like to know what is the approach to extend a

Standard Delivered Abstract Class.

I tried the following approach, but it doesnt seem to work.

I want to add some methods to the standard Abstract Class

CL_CRM_AUI_ENTITY. So i created a copy(not inheritance )

-> ZCL_CRM_AUI_ENTITY and added a new abstract method to this class.

The Class CL_CRM_AUI_ONEORDER implements the methods of the abstract class. I implemented the new method here.

Now in my Application :

The following code works - <b>Reference to the standard delivered abstract class cl_crm_aui_entity.</b>

data : lv_bol_entity type ref to cl_crm_bol_entity lv_aui_entity type ref to cl_crm_aui_entity.

....

....

IF lv_bol_entity is bound.

lv_aui_entity ?= lv_bol_entity.

ENDIF.

The following code <b>does not</b> work and gives me a CX_SY_MOVE_CAST_ERROR.

data : lv_bol_entity type ref to cl_crm_bol_entity,

lv_aui_entity type ref to <i><b>zcl_crm_aui_entity</b></i>.

....

....

IF lv_bol_entity is bound.

lv_aui_entity ?= lv_bol_entity.

CATCH...

ENDCATCH.

ENDIF.

Is the solution then to modify the standard delivered abstract class or can we work around this?

Thanks.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Horst /Klaus

I think I cannot do an inheritance here as the standard class CL_CRM_AUI_ONE_ORDER will not have a reference to the methods of the inherited class.

Is the Decorator approach feasible in ABAP OO, from what i saw from the links, it seems similar to the inheritance approach.

former_member183804
Active Contributor
0 Kudos

Decorators work well if a Class define an interface. Using decorators gives the power to add multiple features which can freely combined without creating all combinations of classes.

If e.g. you want to enable tracing of each method you implement a trace decorator and put in the original implementation. Another decorator may due additonal security checks. If you now want to combine both you just can put the original instance in the first decorator and then in the second. With single inheritance you may need much more classes.

But similar to inheritance, the instances of the base class wont be able to call instances of the encapsulation. The decorator can replace or enrich the base class only.

I wonder why you want to make the original class to use your changes. Is it not sufficient that all programs using your enriched instances work with your additions.

Kind Regards

Klaus

former_member183804
Active Contributor
0 Kudos

Hello Anoop,

a copied class is never move compatible to the original one. If you want to add methods to a class and be compatible then inheritance is the easiest solution.

Another approach maybe the Decorator Pattern

http://www.fluffycat.com/java/JavaNotes-GoFDecorator.html

http://home.earthlink.net/~huston2/dp/decorator.html

Best Regards

Klaus

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

from a fast glimps of your problem, I would say the problem is that you copied the class instead of deriving a subclass. A subclass should work fine.

Regards, Horst