Hi Experts,
I have doubt in singleton. Recently I have created a singleton class for my program using a class-constructor as given below -
CLASS lcl_zus_r5071_dyn DEFINITION CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS: class_constructor,
get_instance EXPORTING r_factory TYPE REF TO lcl_zus_r5071_dyn.
...
PRIVATE SECTION.
CLASS-DATA: factory_instance TYPE REF TO lcl_zus_r5071_dyn.
ENDCLASS.
CLASS lcl_zus_r5071_dyn IMPLEMENTATION.
* Create Instance
METHOD class_constructor.
CREATE OBJECT factory_instance.
ENDMETHOD. "class_constructor
* Send instance to Client -
METHOD get_instance.
r_factory = factory_instance.
ENDMETHOD.
then I get the object reference using below code in client program -
INITIALIZATION.
* Create single tones -
lcl_zus_r5071_dyn=>get_instance( IMPORTING r_factory = go_sel ).
My doubt arise when I saw SAP help and other forum threads for creating singleton. Every blog suggest to use only a static method for both creation of object and sending the same object to caller. Thus I would like to know is there any potential design issue if I use first static constructor for object creation and then a static method to send the reference ?