<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Singleton doubt in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-doubt/m-p/9728526#M1772028</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only limitation to using STATIC constr for implementing the singleton design is that you cannot have any interface params &lt;SPAN __jive_emoticon_name="sad" __jive_macro_name="emoticon" class="jive_macro jive_emote" src="https://community.sap.com/1735/images/emoticons/sad.gif"&gt;&lt;/SPAN&gt; Since the STATIC constr is called by the ABAP runtime environment the developer doesn't have any &lt;SPAN style="font-size: 10pt;"&gt;influence on it, hence no interface params.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;So if your CLASS constr (or simply CONSTRUCTOR) has any params (IMPORTING of course), then you cannot use the static constructor to pass the actual params from the caller &lt;SPAN __jive_emoticon_name="plain" __jive_macro_name="emoticon" class="jive_macro jive_macro_emoticon jive_emote" src="https://community.sap.com/1735/images/emoticons/plain.gif"&gt;&lt;/SPAN&gt; Hence the usage of STATIC constr is restricted in this case.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="color: #333333; font-size: 12px; background-color: #ffffff;"&gt;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 ?&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;&lt;P&gt;It depends on how to want to design your CLASS constr; if you foresee the usage of params then i you should not use CLASS constr to implement singleton, else you can!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IMO the basic idea to design singleton is - &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Define the class instantiation as Private.&lt;/LI&gt;&lt;LI&gt;Define an private attribute (object ref) which is of the type of the singleton class.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How you implement it, depends on the use case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Aug 2013 11:58:38 GMT</pubDate>
    <dc:creator>SuhaSaha</dc:creator>
    <dc:date>2013-08-29T11:58:38Z</dc:date>
    <item>
      <title>Singleton doubt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-doubt/m-p/9728525#M1772027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have doubt in singleton. Recently I have created a singleton class for my program using a class-constructor as given below - &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S52"&gt;CLASS lcl_zus_r5071_dyn &lt;SPAN class="L0S52"&gt;DEFINITION &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;CREATE &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;PRIVATE&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN class="L0S52"&gt;PUBLIC &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;SECTION&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="L0S52"&gt;CLASS-METHODS&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;: &lt;/SPAN&gt;class_constructor&lt;SPAN class="L0S55"&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; get_instance &lt;SPAN class="L0S52"&gt;EXPORTING &lt;/SPAN&gt;r_factory &lt;SPAN class="L0S52"&gt;TYPE &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;REF &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;TO &lt;/SPAN&gt;lcl_zus_r5071_dyn&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S52"&gt;&lt;BR /&gt; &lt;SPAN class="L0S52"&gt;PRIVATE &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;SECTION&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="L0S52"&gt;CLASS-DATA&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;: &lt;/SPAN&gt;factory_instance &lt;SPAN class="L0S52"&gt;TYPE &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;REF &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;TO &lt;/SPAN&gt;lcl_zus_r5071_dyn&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="L0S52"&gt;ENDCLASS&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S52"&gt;CLASS lcl_zus_r5071_dyn IMPLEMENTATION.&lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S31"&gt;* Create Instance&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="L0S52"&gt;METHOD &lt;/SPAN&gt;class_constructor&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="L0S52"&gt;CREATE &lt;/SPAN&gt;OBJECT factory_instance&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="L0S52"&gt;ENDMETHOD&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="L0S31"&gt;"class_constructor&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="L0S31"&gt;* Send instance to Client -&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="L0S52"&gt;METHOD get_instance&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r_factory &lt;SPAN class="L0S55"&gt;= &lt;/SPAN&gt;factory_instance&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;SPAN class="L0S52"&gt;ENDMETHOD&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S31"&gt;&lt;SPAN class="L0S55"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S31"&gt;&lt;SPAN class="L0S55"&gt;then I get the&amp;nbsp; object reference using below code in client program - &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S52"&gt;INITIALIZATION&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="L0S31"&gt;* Create single tones -&lt;/SPAN&gt;&lt;BR /&gt; lcl_zus_r5071_dyn&lt;SPAN class="L0S70"&gt;=&amp;gt;get_instance&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;( &lt;/SPAN&gt;&lt;SPAN class="L0S52"&gt;IMPORTING &lt;/SPAN&gt;r_factory &lt;SPAN class="L0S55"&gt;= &lt;/SPAN&gt;go_sel &lt;SPAN class="L0S55"&gt;)&lt;/SPAN&gt;&lt;SPAN class="L0S55"&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S52"&gt;&lt;SPAN class="L0S55"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S52"&gt;&lt;SPAN class="L0S55"&gt;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 ?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="L0S52"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Aug 2013 11:10:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-doubt/m-p/9728525#M1772027</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-08-29T11:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: Singleton doubt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-doubt/m-p/9728526#M1772028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only limitation to using STATIC constr for implementing the singleton design is that you cannot have any interface params &lt;SPAN __jive_emoticon_name="sad" __jive_macro_name="emoticon" class="jive_macro jive_emote" src="https://community.sap.com/1735/images/emoticons/sad.gif"&gt;&lt;/SPAN&gt; Since the STATIC constr is called by the ABAP runtime environment the developer doesn't have any &lt;SPAN style="font-size: 10pt;"&gt;influence on it, hence no interface params.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;So if your CLASS constr (or simply CONSTRUCTOR) has any params (IMPORTING of course), then you cannot use the static constructor to pass the actual params from the caller &lt;SPAN __jive_emoticon_name="plain" __jive_macro_name="emoticon" class="jive_macro jive_macro_emoticon jive_emote" src="https://community.sap.com/1735/images/emoticons/plain.gif"&gt;&lt;/SPAN&gt; Hence the usage of STATIC constr is restricted in this case.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="color: #333333; font-size: 12px; background-color: #ffffff;"&gt;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 ?&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;&lt;P&gt;It depends on how to want to design your CLASS constr; if you foresee the usage of params then i you should not use CLASS constr to implement singleton, else you can!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IMO the basic idea to design singleton is - &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Define the class instantiation as Private.&lt;/LI&gt;&lt;LI&gt;Define an private attribute (object ref) which is of the type of the singleton class.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How you implement it, depends on the use case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Aug 2013 11:58:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-doubt/m-p/9728526#M1772028</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2013-08-29T11:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Singleton doubt</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-doubt/m-p/9728527#M1772029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Suhas. It clarifies my doubt. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think if I want to use Singleton in inheritence, then I have to plan for a factory method with parameter (Usually Parent/child class name). In that case, class-constructor is of no use.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Aug 2013 14:14:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-doubt/m-p/9728527#M1772029</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-08-29T14:14:25Z</dc:date>
    </item>
  </channel>
</rss>

