Application Development 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: 

Final class inheritance trick...

former_member737583
Participant
0 Kudos

I must write class which inherits from SAP standard final class, but as You now inheritance from final class is impossible.

Is in ABAP any trick, which allow me to inherit trom it?

What's is my goal. This class have properties which are public, but read-only. I must to overwrite them (those properties), and I want to write new class (inheritance) which have "set" methods for this properties or do whatever what allows me change those properties.

For any help I'll reward in points.

Regards, Tomek

9 REPLIES 9

Former Member
0 Kudos

0 Kudos

I know this link, there is written this what I already said:

"When you choose this function, the Inherits from dialog box appears. You can define the inheritance relationship here by specifying the name of the superclass.

You can define the superclass as any class from the class library that is not defined as final."

Former Member
0 Kudos

hi

good

you cant inherit the final class,

go through this link.

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

http://www.sap-press.de/download/dateien/1109/sappress_abap_objects_358.pdf

thanks

mrutyun

former_member183804
Active Contributor
0 Kudos

Hello Tomasz,

there is no trick beside modification.

Regards,

Klaus

0 Kudos

I was afraid that there is no way to archieve my goals

Finaly, I developed "walk around" solution, but it stinks with potencial unpredictable errors.

0 Kudos

Hello Thomas,

I assume you have wrapped the services of the original class-pool in some way. If you dont need the inheritance but only the services you may try something similar to the decorator pattern. I think of on class-pool with exactely the same signature as the original one, a instance member which is a instance of the original class and the default implementation of each method is just a delegation to the original one. The public attributes need to be converted to getter_Methods. The big question left is what do in case of your setter_Methods.

Best Regards,

Klaus

0 Kudos

To state precisly: I'm writing an extension (plugin) to Code Inspector. There every search for tokens (like, FORM, ENDFORM) is based on clas CL_CI_TEST_SCAN. This class have an property: REF_SCAN (Type ref to: CL_CI_SCAN).

I must to implement in every new Code Inspector Extension such functionality:

- when commented @DENY token is found (till @ENDDENY), then all code (all tokens) in file should be omitted by Code Inspector, when @ALLOW (till @ENDALLOW) is found code must to be checked.

So because REF_SCAN have information about tokens in his properties like TOKENS, STATEMENTS, which are READ_ONLY and CL_CI_SCAN is defined as a final class I have no way to overwrite this properties.

Another problem is, that this REF_SCAN is used (sometimes) in written by sap methods of some classes which extends Code Inspecor.

Thatway only one logic reason is to overwite TOKENS, STATEMENTS poperty in REF_SCAN in every extension in the GET method (where data preparation is performed).

But as I said before read_only attributed for property and final mark for class deny me inheritance and deny access to overwrite this properties

Regard, Tomek

0 Kudos

Hello Thomasz,

I assume your are on a older 4.x system as the current version of the class pool cl_ci_test_scan has no final flag.

But I sounds you can use the decorator like approach. It´s basic drawback is performance for the extra delegation method. Within the new getter Methods for the once final attributes you can alter them the way you like is before passing it down to further child classes.

That of course won´t do the trick to alter SAP plug-ins but thats also true for inheritance. So regardless of the approach you have to subclass each SAP check anyway to have that new semantic.

Regards,

Klaus

0 Kudos

?Unfortunatelly I use 4.7

Thanks for all, I'm going to find some infos about decorator pattern in ABAP