<?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/"
		>
<channel>
	<title>Comments on: How to write a Singleton? (2/5)</title>
	<atom:link href="http://www.javablogging.com/how_to_write_a_singleton_2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javablogging.com/how_to_write_a_singleton_2/</link>
	<description>Tracking surprises, features and bugs</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:43:49 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Sumit</title>
		<link>http://www.javablogging.com/how_to_write_a_singleton_2/comment-page-1/#comment-80</link>
		<dc:creator>Sumit</dc:creator>
		<pubDate>Tue, 04 Aug 2009 22:59:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=137#comment-80</guid>
		<description>@ PPOW: I thought Josh Bloch&#039;s suggestion was not 

enum Singleton { INSTANCE }

but 

private static Singleton createInstance() {
       return EnumSet.of ( new Singleton() );
    }</description>
		<content:encoded><![CDATA[<p>@ PPOW: I thought Josh Bloch&#8217;s suggestion was not </p>
<p>enum Singleton { INSTANCE }</p>
<p>but </p>
<p>private static Singleton createInstance() {<br />
       return EnumSet.of ( new Singleton() );<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ppow</title>
		<link>http://www.javablogging.com/how_to_write_a_singleton_2/comment-page-1/#comment-78</link>
		<dc:creator>ppow</dc:creator>
		<pubDate>Tue, 04 Aug 2009 18:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=137#comment-78</guid>
		<description>It is simpler, but you lose the advantage of having control over the way the singleton is accessed. With a get method it will be easier to incorporate future changes -  what if you change your mind and want to have a lazy initialization? Maybe want to add logging on every get / count the numbers of gets? Maybe at some point you will want to drop the singleton quality and just give new objects every time someone request one? Without a access method you do not have those possibilities...</description>
		<content:encoded><![CDATA[<p>It is simpler, but you lose the advantage of having control over the way the singleton is accessed. With a get method it will be easier to incorporate future changes &#8211;  what if you change your mind and want to have a lazy initialization? Maybe want to add logging on every get / count the numbers of gets? Maybe at some point you will want to drop the singleton quality and just give new objects every time someone request one? Without a access method you do not have those possibilities&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kees</title>
		<link>http://www.javablogging.com/how_to_write_a_singleton_2/comment-page-1/#comment-76</link>
		<dc:creator>Kees</dc:creator>
		<pubDate>Tue, 04 Aug 2009 16:09:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=137#comment-76</guid>
		<description>Simpler is to have the INSTANCE public:


public class Singleton {
    public static final Singleton INSTANCE = new Singleton();

    // Remember that Singleton constructor should be private
    private Singleton() {}
}</description>
		<content:encoded><![CDATA[<p>Simpler is to have the INSTANCE public:</p>
<p>public class Singleton {<br />
    public static final Singleton INSTANCE = new Singleton();</p>
<p>    // Remember that Singleton constructor should be private<br />
    private Singleton() {}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ppow</title>
		<link>http://www.javablogging.com/how_to_write_a_singleton_2/comment-page-1/#comment-65</link>
		<dc:creator>ppow</dc:creator>
		<pubDate>Tue, 28 Jul 2009 17:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=137#comment-65</guid>
		<description>Yes, I know Bloch&#039;s opinion about that but I do not agree with him because of several things: 
- with enum your singleton cannot extend any other class (you can only implement interfaces)
- your singleton object is exactly of the enum class that contains it (you cannot separate the class that gives you access to singleton with the singleton class)
- your singleton is of type Enum and because of that it has many useless and confusing methods (oridinal(), name()...)
- you do not control access to the singleton by a get/access method (see the comments about benefits from method like that in Effective Java #1)
The only gain of doing this with enum is the serialization issue... but if you do need that I would strongly suggest dealing with readResolve() as it is more readable what kind of issue you are solving this way.</description>
		<content:encoded><![CDATA[<p>Yes, I know Bloch&#8217;s opinion about that but I do not agree with him because of several things:<br />
- with enum your singleton cannot extend any other class (you can only implement interfaces)<br />
- your singleton object is exactly of the enum class that contains it (you cannot separate the class that gives you access to singleton with the singleton class)<br />
- your singleton is of type Enum and because of that it has many useless and confusing methods (oridinal(), name()&#8230;)<br />
- you do not control access to the singleton by a get/access method (see the comments about benefits from method like that in Effective Java #1)<br />
The only gain of doing this with enum is the serialization issue&#8230; but if you do need that I would strongly suggest dealing with readResolve() as it is more readable what kind of issue you are solving this way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Macpherson</title>
		<link>http://www.javablogging.com/how_to_write_a_singleton_2/comment-page-1/#comment-64</link>
		<dc:creator>Dave Macpherson</dc:creator>
		<pubDate>Tue, 28 Jul 2009 14:53:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=137#comment-64</guid>
		<description>The enum implementation certainly is the simplest, and if your singleton is also serializable, then unless you provide a readResolve() implementation, it&#039;s also the only way to guarantee that it forever remains a singleton (see Item #3 of Bloch&#039;s Effective Java).</description>
		<content:encoded><![CDATA[<p>The enum implementation certainly is the simplest, and if your singleton is also serializable, then unless you provide a readResolve() implementation, it&#8217;s also the only way to guarantee that it forever remains a singleton (see Item #3 of Bloch&#8217;s Effective Java).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dimitris Andreou</title>
		<link>http://www.javablogging.com/how_to_write_a_singleton_2/comment-page-1/#comment-59</link>
		<dc:creator>Dimitris Andreou</dc:creator>
		<pubDate>Thu, 23 Jul 2009 02:38:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=137#comment-59</guid>
		<description>&gt;I show today how to write it in a simplest and safest way possible

Actually, this is the simplest and safest way possible:

enum Singleton { INSTANCE }</description>
		<content:encoded><![CDATA[<p>&gt;I show today how to write it in a simplest and safest way possible</p>
<p>Actually, this is the simplest and safest way possible:</p>
<p>enum Singleton { INSTANCE }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

