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

Re: Determine class name used for calling a static method

$
0
0

Hi Naimesh,

 

Thanks for the input. Background is that this method is part of an abstract superclass, and it should manage how/what subclasses may be instantiated. So at the time of the call no instance of any sort is known to the caller.

 

The ideal 'OO way' would be a factory class returning an interface reference, but there's a long-winded reason for implementing the same idea in an inheritance tree with a static method at the top.

 

I did tinker around with having the top level class as a singleton instance, not too dissimilar form your idea. But that added more complexity for the caller so no joy there.

 

My current best approach is to use a standalone factory class with a separate method for each subclass in my tree that takes the input and adds the class name to the call to the static method in question.

Anyone who creates a subclass would have to create a corresponding factory method. Clunky but workable:

ZCL_OBJ_FACTORY=>GET_SUB1( somedata )

 

looks better than the really clunky:

ZCL_SUB1=>GET_INSTANCE( i_class = 'ZCL_SUB1'  i_somedata = somedata ).

(which is now hidden in each factory method...)

 

I'll leave this open for ideas.

 

Thanks,

Mike


Viewing all articles
Browse latest Browse all 9091

Trending Articles



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