<?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: Global singleton class - public or protected/private instance generation? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309331#M1918289</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;Ilya Klopkov wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I'm confused, that guidelines contradict each other...&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure how they contradict? The guidelines refer to the "visibility section" of the CONSTRUCTOR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;Always declare the &lt;SPAN style="text-decoration: underline;"&gt;instance constructor&lt;/SPAN&gt; of a global class in its &lt;SPAN style="text-decoration: underline;"&gt;public visibility section&lt;/SPAN&gt; and &lt;SPAN style="text-decoration: underline;"&gt;independently&lt;/SPAN&gt; of the &lt;SPAN style="text-decoration: underline;"&gt;instantiation specified by the &lt;SPAN class="qtext"&gt;CREATE&lt;/SPAN&gt; addition&lt;/SPAN&gt; in the class definition. &lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The commonly used CL_SALV_TABLE class, uses a factory to generate the instance. The instantiation level is pvt. =&amp;gt; no external agent can create an instance of the class&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/jiveimages/821567" /&gt;&lt;/P&gt;&lt;P&gt;But the CONSTRUCTOR is defined in the public visibility level. I think that the programming guideline is referring to this part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/jiveimages/821568" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SAP guideline answers your question. It states &amp;amp; i quote -&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;With the &lt;SPAN style="text-decoration: underline;"&gt;CREATE PRIVATE&lt;/SPAN&gt; addition, objects can only be created by the class itself. The restriction of the object creation to the class itself is useful in connection with the &lt;SPAN style="text-decoration: underline;"&gt;singleton design pattern&lt;/SPAN&gt;, for example, where the class itself performs the object creation. &lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Refer: &lt;A href="http://help.sap.com/abapdocu_731/en/abeninstance_constructor_guidl.htm" title="http://help.sap.com/abapdocu_731/en/abeninstance_constructor_guidl.htm"&gt;ABAP Keyword Documentation&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS - The agent class(CA* classes) of persistence classes are singleton. You can refer to their definition for further info.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Oct 2015 11:16:39 GMT</pubDate>
    <dc:creator>SuhaSaha</dc:creator>
    <dc:date>2015-10-30T11:16:39Z</dc:date>
    <item>
      <title>Global singleton class - public or protected/private instance generation?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309328#M1918286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello colleagues,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Recently, in abapdocu I read a guideline that describes a rule: "Declare the instance constructor in the public visibility section." with an exсeption: "The technical restrictions mentioned only apply to the processing of global classes.".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Okay, clear. But what about global singleton classes? Should we also use public section for constructors of such classes? I thought that protected or private instance generation should be defined for this pattern &lt;SPAN __jive_emoticon_name="confused" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_emote jive_macro" src="https://community.sap.com/1348/images/emoticons/confused.gif"&gt;&lt;/SPAN&gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ilya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2015 08:40:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309328#M1918286</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-10-30T08:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Global singleton class - public or protected/private instance generation?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309329#M1918287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;I thought that protected or private instance generation should be defined for this pattern&lt;/P&gt;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Absolutely correct. If the instance creation is Public, then you can never impose the "singleton" behaviour!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you are confusing "instantiation level" with "visibility".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When defining a class as singleton i set the instantiation level to "Private/Protected" depending on the requirement &amp;amp; never to Public. You can still create the "Constructor" in the PUBLIC "visibility"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As of ABAP 7.0 EhP2 you can define the CONSTRUCTOR in all visibility areas. (Ref. &lt;A href="http://help.sap.com/abapdocu_740/en/abennews-71-abap-objects.htm#!ABAP_MODIFICATION_1@1@" title="http://help.sap.com/abapdocu_740/en/abennews-71-abap-objects.htm#!ABAP_MODIFICATION_1@1@"&gt;ABAP Keyword Documentation&lt;/A&gt;).&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>Fri, 30 Oct 2015 09:27:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309329#M1918287</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2015-10-30T09:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Global singleton class - public or protected/private instance generation?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309330#M1918288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm confused, that guidelines contradict each other...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2015 10:50:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309330#M1918288</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-10-30T10:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Global singleton class - public or protected/private instance generation?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309331#M1918289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;Ilya Klopkov wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I'm confused, that guidelines contradict each other...&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure how they contradict? The guidelines refer to the "visibility section" of the CONSTRUCTOR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;Always declare the &lt;SPAN style="text-decoration: underline;"&gt;instance constructor&lt;/SPAN&gt; of a global class in its &lt;SPAN style="text-decoration: underline;"&gt;public visibility section&lt;/SPAN&gt; and &lt;SPAN style="text-decoration: underline;"&gt;independently&lt;/SPAN&gt; of the &lt;SPAN style="text-decoration: underline;"&gt;instantiation specified by the &lt;SPAN class="qtext"&gt;CREATE&lt;/SPAN&gt; addition&lt;/SPAN&gt; in the class definition. &lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The commonly used CL_SALV_TABLE class, uses a factory to generate the instance. The instantiation level is pvt. =&amp;gt; no external agent can create an instance of the class&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/jiveimages/821567" /&gt;&lt;/P&gt;&lt;P&gt;But the CONSTRUCTOR is defined in the public visibility level. I think that the programming guideline is referring to this part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/jiveimages/821568" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The SAP guideline answers your question. It states &amp;amp; i quote -&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;With the &lt;SPAN style="text-decoration: underline;"&gt;CREATE PRIVATE&lt;/SPAN&gt; addition, objects can only be created by the class itself. The restriction of the object creation to the class itself is useful in connection with the &lt;SPAN style="text-decoration: underline;"&gt;singleton design pattern&lt;/SPAN&gt;, for example, where the class itself performs the object creation. &lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Refer: &lt;A href="http://help.sap.com/abapdocu_731/en/abeninstance_constructor_guidl.htm" title="http://help.sap.com/abapdocu_731/en/abeninstance_constructor_guidl.htm"&gt;ABAP Keyword Documentation&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS - The agent class(CA* classes) of persistence classes are singleton. You can refer to their definition for further info.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2015 11:16:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309331#M1918289</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2015-10-30T11:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Global singleton class - public or protected/private instance generation?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309332#M1918290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;Suhas Saha wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;BLOCKQUOTE class="jive-quote"&gt;
&lt;P&gt;Always declare the &lt;SPAN style="text-decoration: underline;"&gt;instance constructor&lt;/SPAN&gt; of a global class in its &lt;SPAN style="text-decoration: underline;"&gt;public visibility section&lt;/SPAN&gt; and &lt;SPAN data-select-like-a-boss="1" style="text-decoration: underline;"&gt;&lt;STRONG style="color: #ffff00; text-decoration: underline;"&gt;&lt;SPAN style="color: #000000; text-decoration: underline;"&gt;independently&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt; of the &lt;SPAN style="text-decoration: underline;"&gt;instantiation specified by the &lt;SPAN class="qtext"&gt;CREATE&lt;/SPAN&gt; addition&lt;/SPAN&gt; in the class definition. &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;That explains everything &lt;SPAN __jive_emoticon_name="happy" __jive_macro_name="emoticon" class="jive_emote jive_macro" src="https://community.sap.com/1348/images/emoticons/happy.gif"&gt;&lt;/SPAN&gt;. Seems like I understood it in a wrong way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Oct 2015 11:49:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-singleton-class-public-or-protected-private-instance-generation/m-p/11309332#M1918290</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-10-30T11:49:27Z</dc:date>
    </item>
  </channel>
</rss>

