<?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 singleton concept in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284806#M497778</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;  Please anybody explain me about singleton concept in abap objects,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks n Regards&lt;/P&gt;&lt;P&gt;vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 14 May 2007 08:18:36 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-14T08:18:36Z</dc:date>
    <item>
      <title>singleton concept</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284806#M497778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;  Please anybody explain me about singleton concept in abap objects,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks n Regards&lt;/P&gt;&lt;P&gt;vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 May 2007 08:18:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284806#M497778</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-14T08:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: singleton concept</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284807#M497779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;      Singleton means having one instance and making sure that only that instance is used by all the programs or modules. This is generally acheived by making the class instatitation as Private and having an instance attribute in the class of its own type and having a method something like GET_INSTANCE which creates and returns the intance if the class if the instance is already not there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sesh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Seshatalpasai Madala&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 May 2007 08:21:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284807#M497779</guid>
      <dc:creator>seshatalpasai_madala</dc:creator>
      <dc:date>2007-05-14T08:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: singleton concept</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284808#M497780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Vijay&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The singleton concept is a general &amp;lt;b&amp;gt;design pattern&amp;lt;/b&amp;gt; of object-orientation and not specific to ABAP Objects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to look at a concrete sample in ABAP objects have a look at the OO-based persistance services:&lt;/P&gt;&lt;P&gt;&amp;lt;a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/fd/022008bc9311d4b2e80050dadfb92b/content.htm"&amp;gt;Components of the Persistence Service&amp;lt;/a&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &amp;lt;b&amp;gt;class agent&amp;lt;/b&amp;gt; is realised as singleton.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 May 2007 09:31:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284808#M497780</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2007-05-14T09:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: singleton concept</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284809#M497781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to elaborate on what Sesh mentioned, A Singleton class is one that can only be instantiated once during the runtime of a program. Typical examples would be Classes that provide services(Persistance), or classes that provide resource pools(BADI Adapters, Shared Connections, etc.)&lt;/P&gt;&lt;P&gt;Since normal classes can be instantiated any number of times,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CLASS lcl_normal DEFINITION.
  PUBLIC SECTION.
    DATA: v type i.
    METHODS: disp_v.
ENDCLASS.

CLASS lcl_normal IMPLEMENTATION.
  METHOD disp_v.
    WRITE:/ v.
  ENDMETHOD.
ENDCLASS.

*__Report Code__*

DATA: r1 TYPE REF TO lcl_normal,
          r2 TYPE REF TO lcl_normal.

CREATE OBJECT r1.
r1-&amp;gt;v = 10.

CREATE OBJECT r2. "Possible because class is not singleton
r2-&amp;gt;v = 20.

r1-&amp;gt;disp_v( ).
r2-&amp;gt;disp_v( ). " Also possible&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If we have to redesign the above class to make it singleton, in other words, irrespective of how many times the program uses the class, only a single shared instance will be reused, we have to prevent the class from being reinstantiated, we start by preventing calls to the constructor from outside of the class, ie: Only the class itself can create it's own instance!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CLASS lcl_singleton DEFINITION CREATE PRIVATE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next step, now that calling programs cannot "CREATE OBJECT" our class, we provide an alternative to this...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CLASS lcl_singleton DEFINITION CREATE PRIVATE.
   PUBLIC SECTION.
      CLASS-DATA: singleton TYPE REF TO lcl_singleton READ-ONLY.
      DATA: v type i.
      CLASS-METHODS: class_constructor.
      METHODS: disp_v.
ENDCLASS.

CLASS lcl_singleton IMPLEMENTATION.
  METHOD class_constructor.

     CREATE OBJECT singleton. "Can be executed only once

  ENDMETHOD.

  METHOD disp_v.

    WRITE:/ v.

  ENDMETHOD.
ENDCLASS.

*__Report Code__*
DATA: r1 TYPE REF TO lcl_singleton,
          r2 TYPE REF TO lcl_singleton.

*Create object r1 not possible!
r1 = lcl_singleton=&amp;gt;singleton. " The only way to retrieve an instance
r2 = lcl_singleton=&amp;gt;singleton.
r1-&amp;gt;v = 10.
r1-&amp;gt;disp_v( ).
r2-&amp;gt;disp_v( ). "Will also print 10
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And that's how it goes !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dushyant Shetty&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. Did not get the time to syntax-check, please check before using code !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 May 2007 09:47:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/singleton-concept/m-p/2284809#M497781</guid>
      <dc:creator>dustyplanet</dc:creator>
      <dc:date>2007-05-14T09:47:29Z</dc:date>
    </item>
  </channel>
</rss>

