Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2895

Re: Determine class name used for calling a static method

$
0
0

Hi Horst,

 

Great, so two parts of the SAP Help give mixed messages

 

Of course as SAP created ABAP, they are at liberty to implement their own views of OO. If redefinition of static methods were allowed - as it is in Java - then all this would not be an issue. I accept that SAP have made the decision not to allow it.


Static methods are not completely detached from their class, they form part of the scope of the other class components and can access e.g. a protected static attribute of the class. So even though there is no object, static components form part of the class 'bubble' (I'm writing a diagram here ).

 

So although technically the runtime redirects the call to the superclass, semantically it is wrong, because the intent of someone who writes ZCL_SUB=> is to touch class ZCL_SUB, otherwise s/he could just write ZCL_SUPER.

 

Regarding a static constructor, there are no objects and its task is to set the static attributes before they are needed the first time. And that is fullfilled in ABAP. Prove me wrong.

This is precisely what isn't happening and what creates the confusion. The code specifically refers to class ZCL_SUB, because I want ZCL_SUB's class constructor to execute. It sets different attributes to ZCL_SUPER. But I still end up with the attributes of ZCL_SUPER. This is the bit that is counterintuitive.

 

Regards,

Mike


Viewing all articles
Browse latest Browse all 2895

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>