<?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: Singletons Are Evil Part 2</title>
	<atom:link href="http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/</link>
	<description>We got both kinds. We got Mac and Windows.</description>
	<lastBuildDate>Sat, 11 May 2013 05:23:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: codematrix</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-90</link>
		<dc:creator>codematrix</dc:creator>
		<pubDate>Sat, 11 Aug 2012 16:42:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-90</guid>
		<description>It&#039;s not that singletons themselves are bad but the GOF design pattern is. The only really argument that is valid is that the GOF design pattern doesn&#039;t lend itself in regards to testing, especially if tests are run in parallel.
 
Using a single instance of an class is a valid construct as long as you apply the following means in code:
 
 1. Make sure the class that will be used as a singleton implements an interface. This allows stubs or mocks to be implemented using the same interface
 
 2. Make sure that the Singleton is thread-safe if necessary.  That&#039;s a given.
 
 3. The singleton should be simple in nature and not overly complicated.
 
 4. During the RUNTIME of you application, where singletons need to be passed to a given object, use a class factory that builds the depending object and have the class factory pass the global singleton instance to the depending object that requires it.
 
 5. During TESTING and to ensure deterministic behavior, create the singleton class as separate instance as either the actual class itself or a stub/mock that implements its behavior and pass it as is to the object that requires it. Don&#039;t USE the class factor that creates that object under test that needs the signleton during test as it will pass the global singleton  instance, which defeats the purpose.
 
We&#039;ve used Singletons in our solutions with a great deal of success that are not tightly bound, extensible, replaceable and are testable, ensuring deterministic behavior in parallel test run streams. 
 
codematrix</description>
		<content:encoded><![CDATA[<p>It&#8217;s not that singletons themselves are bad but the GOF design pattern is. The only really argument that is valid is that the GOF design pattern doesn&#8217;t lend itself in regards to testing, especially if tests are run in parallel.</p>
<p>Using a single instance of an class is a valid construct as long as you apply the following means in code:</p>
<p> 1. Make sure the class that will be used as a singleton implements an interface. This allows stubs or mocks to be implemented using the same interface</p>
<p> 2. Make sure that the Singleton is thread-safe if necessary.  That&#8217;s a given.</p>
<p> 3. The singleton should be simple in nature and not overly complicated.</p>
<p> 4. During the RUNTIME of you application, where singletons need to be passed to a given object, use a class factory that builds the depending object and have the class factory pass the global singleton instance to the depending object that requires it.</p>
<p> 5. During TESTING and to ensure deterministic behavior, create the singleton class as separate instance as either the actual class itself or a stub/mock that implements its behavior and pass it as is to the object that requires it. Don&#8217;t USE the class factor that creates that object under test that needs the signleton during test as it will pass the global singleton  instance, which defeats the purpose.</p>
<p>We&#8217;ve used Singletons in our solutions with a great deal of success that are not tightly bound, extensible, replaceable and are testable, ensuring deterministic behavior in parallel test run streams. </p>
<p>codematrix</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shopping cart software</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-79</link>
		<dc:creator>shopping cart software</dc:creator>
		<pubDate>Tue, 24 Jan 2012 14:10:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-79</guid>
		<description>Well great addition to my knowledge, its good to keep learning all the time.</description>
		<content:encoded><![CDATA[<p>Well great addition to my knowledge, its good to keep learning all the time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Domain register</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-75</link>
		<dc:creator>Domain register</dc:creator>
		<pubDate>Fri, 23 Dec 2011 06:54:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-75</guid>
		<description>Great content I keep learning new things every day from post like these. Good stuff!</description>
		<content:encoded><![CDATA[<p>Great content I keep learning new things every day from post like these. Good stuff!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kerrrtivolsafdf</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-32</link>
		<dc:creator>kerrrtivolsafdf</dc:creator>
		<pubDate>Sat, 26 Mar 2011 16:43:22 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-32</guid>
		<description>Thanks pal. This is nice knowing</description>
		<content:encoded><![CDATA[<p>Thanks pal. This is nice knowing</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asics Gel</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-31</link>
		<dc:creator>Asics Gel</dc:creator>
		<pubDate>Sat, 26 Mar 2011 04:04:15 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-31</guid>
		<description>great blog post, i surely adore this site, keep on it.</description>
		<content:encoded><![CDATA[<p>great blog post, i surely adore this site, keep on it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claudio Lassala</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-21</link>
		<dc:creator>Claudio Lassala</dc:creator>
		<pubDate>Fri, 28 Aug 2009 22:19:07 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-21</guid>
		<description>Yeah, Deliverance by Opeth is awesome!! *That* is evil.  :)</description>
		<content:encoded><![CDATA[<p>Yeah, Deliverance by Opeth is awesome!! *That* is evil.  <img src='http://lostechies.com/scottdensmore/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CNemo</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-20</link>
		<dc:creator>CNemo</dc:creator>
		<pubDate>Fri, 21 Aug 2009 14:37:37 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-20</guid>
		<description>How does it prove that singleton is evil? :-0</description>
		<content:encoded><![CDATA[<p>How does it prove that singleton is evil? :-0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harry M</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-19</link>
		<dc:creator>Harry M</dc:creator>
		<pubDate>Fri, 14 Aug 2009 08:44:21 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-19</guid>
		<description>You can use a static constructor on the class to initialise the instance: http://stackoverflow.com/questions/7095/is-the-c-static-constructor-thread-safe</description>
		<content:encoded><![CDATA[<p>You can use a static constructor on the class to initialise the instance: <a href="http://stackoverflow.com/questions/7095/is-the-c-static-constructor-thread-safe" rel="nofollow">http://stackoverflow.com/questions/7095/is-the-c-static-constructor-thread-safe</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Smith</title>
		<link>http://lostechies.com/scottdensmore/2009/08/14/singletons-are-evil-part-2/#comment-18</link>
		<dc:creator>Eric Smith</dc:creator>
		<pubDate>Fri, 14 Aug 2009 08:12:05 +0000</pubDate>
		<guid isPermaLink="false">/blogs/scottdensmore/archive/2009/08/13/singletons-are-evil-part-2.aspx#comment-18</guid>
		<description>Shouldn&#039;t line 19 of the third listing be:

instance = new Foo(new Bar(new Baz()))</description>
		<content:encoded><![CDATA[<p>Shouldn&#8217;t line 19 of the third listing be:</p>
<p>instance = new Foo(new Bar(new Baz()))</p>
]]></content:encoded>
	</item>
</channel>
</rss>
