cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Inheritance

BGarcia
Active Contributor
0 Likes
332

Hello Everybody,

I just one doubt concerning inheritance. For example, the class CL_CRM_IC_SRVTHEAD_IMPL has private methods.

If I create one class, and point CL_CRM_IC_SRVTHEAD_IMPL as his superclass, this methods are not inherited.

Must I implement them by hand in the new class, in the same way they're define in superclass? Or when their are called in application, they're gonna be called CL_CRM_IC_SRVTHEAD_IMPL methods.

Best Regards,

Bruno Garcia

Accepted Solutions (0)

Answers (5)

Answers (5)

rainer_liebisch
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Bruno,

you don't have to rewrite the classes. Just use the cast operator. Let me give you an example:

You have a class Z_CL_1 which inherits from CL_1 and a class Z_CL_2 which inherits from CL_2. In CL_2 you have the attribute:

attr type ref to CL_1.

When you need attr in a method in Z_CL_2, you can write in that method:

method mymethod.

data: z_attr type ref to Z_CL_1.

z_attr ?= attr.

...

endmethod.

When you need it in your programme, you can do the same. Just make sure that an instance of Z_CL_1 exists before you use the cast.

Regards,

Rainer

...

BGarcia
Active Contributor
0 Likes

I have created a Z1_CL_CRM_IC_SRVTHEAD_CN01 class , that inherits CL_CRM_IC_SRVTHEAD_CN01. In there, I added a new attribute and four methods. OK.

So now I have to point this class in his context. His context is class CL_CRM_IC_SRVTHEAD_CTXT. I created Z1_CL_CRM_IC_SRVTHEAD_CTXT that inherits this class, but because of the attribute BTCATEGORY (that points to CL_CRM_IC_SRVTHEAD_CN01) is inherited, I can't change it to my new class.

If I can't change it, so...there's no utility of inherate context nodes?? must I always make a copy of the standart context?

After that...I still need to change CRM_IC_SRVTHEAD_IMPL, that creates a context. The attribute TYPED_CONTEXT is also inherited by is superclass, and therefore I can't change it too...

That's why I asked the above question...

Best Regards and Thank you

Bruno Garcia

rainer_liebisch
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Bruno,

no that's not possible and also doesn't make sense, because otherwise things like casting can't work.

Why don't you add a new attribute to your subclass with the reference you need?

Regards,

Rainer

BGarcia
Active Contributor
0 Likes

Hello everybody.

Thanks for the response, but may I ask one more thing?

If we inherate atributes for the superclass, can we change, for example, the reference type of those atributes inherated in our new class. I get a grey area that don't let me change the attributes inherated...

Or I have to build the upper class too?

Best Regards

Bruno Garcia

rainer_liebisch
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Bruno,

that's the way it should be. You have a public section, a protected section and a private section. To the public section everyone has access, to the protected section only the class and its subclasses have access, and to the private section only the class itself has access, so there is no inheritance for private methods and attributes.

Regards,

Rainer