<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Singleton &#8211; instantiate just ONE OBJECT</title>
	<atom:link href="http://ashrafur.wordpress.com/2008/08/13/singleton-instantiate-just-one-object/feed/" rel="self" type="application/rss+xml" />
	<link>http://ashrafur.wordpress.com/2008/08/13/singleton-instantiate-just-one-object/</link>
	<description>Weblogs of Ashrafur Rahaman</description>
	<lastBuildDate>Fri, 18 Dec 2009 10:53:38 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: ashraf</title>
		<link>http://ashrafur.wordpress.com/2008/08/13/singleton-instantiate-just-one-object/#comment-156</link>
		<dc:creator>ashraf</dc:creator>
		<pubDate>Sun, 31 Aug 2008 07:41:22 +0000</pubDate>
		<guid isPermaLink="false">http://ashrafur.wordpress.com/?p=149#comment-156</guid>
		<description>Hi hasan,
Thanks for your nice idea sharing and comments.
In c# we can use sealed instead of final. But it&#039;s not recommended to use as lazy loading what already mentioned. 

Thanks to share your DI framework idea with me, I did not know about that.</description>
		<content:encoded><![CDATA[<p>Hi hasan,<br />
Thanks for your nice idea sharing and comments.<br />
In c# we can use sealed instead of final. But it&#8217;s not recommended to use as lazy loading what already mentioned. </p>
<p>Thanks to share your DI framework idea with me, I did not know about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nhm tanveer hossain khan (hasan)</title>
		<link>http://ashrafur.wordpress.com/2008/08/13/singleton-instantiate-just-one-object/#comment-155</link>
		<dc:creator>nhm tanveer hossain khan (hasan)</dc:creator>
		<pubDate>Sat, 30 Aug 2008 09:03:08 +0000</pubDate>
		<guid isPermaLink="false">http://ashrafur.wordpress.com/?p=149#comment-155</guid>
		<description>i presume, lazy loading is not your intention.
i would write the following code which ensure thread safety as well as less code.

public class Singleton {
  private static final Singleton INSTANCE = new Singleton();

  private Singleton() { }

  public static Singleton getInstance() {
    return INSTANCE;
  }
}

this work fine with java, but don&#039;t have any idea about .NET. pretending it should work. 

btw, as in java, we are not extensively using singleton pattern rather we all are using dependency injection pattern.

let&#039;s say the above class singleton won&#039;t keep INSTANCE variable any more. 

rather our dependency injection framework will manage it&#039;s instance and will inject through setter method of our required class.

let&#039;s say.

class ServiceA { 
  // do bla bla bla
}

class ServiceAConsumer {
  private final ServiceA mServiceA;

  public ServiceAConsumer(final ServiceA pServiceA) {
    mServiceA = pServiceA;
  }

  // do my job with ServiceA instance
  // ie. 
}

without DI framework we would do the following code - 
class ServiceAConsumer {
  private final ServiceA mServiceA;

  public ServiceAConsumer() {
    mServiceA = ServiceA.getInstance();
  }

  // do my job with ServiceA instance
  // ie. 
}

as you see we are binding our dependency in implementation level, let&#039;s say ServiceA is an interface and ServiceAImpl is the concrete implementation. so you would write ServiceAImpl.getInstance(). when you have many services like this, it will become hard to maintain. thats why we are giving more priority on DI.

i think you will dig more about this area. 
btw nice write up. keep up your good works.</description>
		<content:encoded><![CDATA[<p>i presume, lazy loading is not your intention.<br />
i would write the following code which ensure thread safety as well as less code.</p>
<p>public class Singleton {<br />
  private static final Singleton INSTANCE = new Singleton();</p>
<p>  private Singleton() { }</p>
<p>  public static Singleton getInstance() {<br />
    return INSTANCE;<br />
  }<br />
}</p>
<p>this work fine with java, but don&#8217;t have any idea about .NET. pretending it should work. </p>
<p>btw, as in java, we are not extensively using singleton pattern rather we all are using dependency injection pattern.</p>
<p>let&#8217;s say the above class singleton won&#8217;t keep INSTANCE variable any more. </p>
<p>rather our dependency injection framework will manage it&#8217;s instance and will inject through setter method of our required class.</p>
<p>let&#8217;s say.</p>
<p>class ServiceA {<br />
  // do bla bla bla<br />
}</p>
<p>class ServiceAConsumer {<br />
  private final ServiceA mServiceA;</p>
<p>  public ServiceAConsumer(final ServiceA pServiceA) {<br />
    mServiceA = pServiceA;<br />
  }</p>
<p>  // do my job with ServiceA instance<br />
  // ie.<br />
}</p>
<p>without DI framework we would do the following code &#8211;<br />
class ServiceAConsumer {<br />
  private final ServiceA mServiceA;</p>
<p>  public ServiceAConsumer() {<br />
    mServiceA = ServiceA.getInstance();<br />
  }</p>
<p>  // do my job with ServiceA instance<br />
  // ie.<br />
}</p>
<p>as you see we are binding our dependency in implementation level, let&#8217;s say ServiceA is an interface and ServiceAImpl is the concrete implementation. so you would write ServiceAImpl.getInstance(). when you have many services like this, it will become hard to maintain. thats why we are giving more priority on DI.</p>
<p>i think you will dig more about this area.<br />
btw nice write up. keep up your good works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anil</title>
		<link>http://ashrafur.wordpress.com/2008/08/13/singleton-instantiate-just-one-object/#comment-148</link>
		<dc:creator>Anil</dc:creator>
		<pubDate>Wed, 20 Aug 2008 09:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://ashrafur.wordpress.com/?p=149#comment-148</guid>
		<description>To be threadsafe for a class a simple implementation required would be:

public class Singleton
    {
        private static Singleton UniqueInstance;
        private static Object syncLock = new Object();

        private Singleton()
        {
        }

        public static Singleton GetInstance()
        {
            lock(syncLock)
            {
                if (UniqueInstance == null)
                {
                    UniqueInstance = new Singleton();
                }
            }
            return UniqueInstance;
        }
    }</description>
		<content:encoded><![CDATA[<p>To be threadsafe for a class a simple implementation required would be:</p>
<p>public class Singleton<br />
    {<br />
        private static Singleton UniqueInstance;<br />
        private static Object syncLock = new Object();</p>
<p>        private Singleton()<br />
        {<br />
        }</p>
<p>        public static Singleton GetInstance()<br />
        {<br />
            lock(syncLock)<br />
            {<br />
                if (UniqueInstance == null)<br />
                {<br />
                    UniqueInstance = new Singleton();<br />
                }<br />
            }<br />
            return UniqueInstance;<br />
        }<br />
    }</p>
]]></content:encoded>
	</item>
</channel>
</rss>
