<?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: Where Have All the Singletons Gone?</title>
	<atom:link href="http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Fri, 30 Jul 2010 03:59:03 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Linkroll &#171; Notes worth sharing</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-2728</link>
		<dc:creator>Linkroll &#171; Notes worth sharing</dc:creator>
		<pubDate>Sun, 03 Jan 2010 18:06:17 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-2728</guid>
		<description>[...] http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/ and http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/, “why singletons cause [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/" rel="nofollow">http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/</a> and <a href="http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/" rel="nofollow">http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/</a>, “why singletons cause [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-2574</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Wed, 09 Dec 2009 20:42:30 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-2574</guid>
		<description>@misko,

I agree with you completely about servlets, which is why I imagine almost every java web framework in existence replaces them with something else.  The reason I mentioned them is only because the post refers to them directly:

&quot;At run-time an HTTP request comes in. The servlet has a reference to RequestFactory and calls build().&quot;

It glosses over how the servlet gets the reference to the RequestFactory.  I only mention this because if someone comes to this post and is learning why they shouldn&#039;t use singletons for everything, they will get stuck wondering how to jump through that final hoop.

Now, while I personally don&#039;t like using servlets, there is a way to give them a dynamic context by using an synchronized initialization servlet that puts an Application instance into the ServletContext.  This Application object would hold / provide all of the application necessary configurable objects (offline queue, authenticator, requestFactory, etc).

For testing, the instance of the Application object can be changed with a different class that provides a different implementation, so you would have your TestApplication instance to replace your ProductionApplication instance.

This still doesn&#039;t make code that is embedded inside servlets easy to unit test though, since you still need the servlet container. 

I have never used the design I have just mentioned, so I am not sure if it has serious problems or not, but it would be easier to refactor to if someone is migrating an existing Servlet based application (easy enough that it seems like a free way to remove singleton dependencies that would be easier than replacing an existing apps use of servlets all together).</description>
		<content:encoded><![CDATA[<p>@misko,</p>
<p>I agree with you completely about servlets, which is why I imagine almost every java web framework in existence replaces them with something else.  The reason I mentioned them is only because the post refers to them directly:</p>
<p>&#8220;At run-time an HTTP request comes in. The servlet has a reference to RequestFactory and calls build().&#8221;</p>
<p>It glosses over how the servlet gets the reference to the RequestFactory.  I only mention this because if someone comes to this post and is learning why they shouldn&#8217;t use singletons for everything, they will get stuck wondering how to jump through that final hoop.</p>
<p>Now, while I personally don&#8217;t like using servlets, there is a way to give them a dynamic context by using an synchronized initialization servlet that puts an Application instance into the ServletContext.  This Application object would hold / provide all of the application necessary configurable objects (offline queue, authenticator, requestFactory, etc).</p>
<p>For testing, the instance of the Application object can be changed with a different class that provides a different implementation, so you would have your TestApplication instance to replace your ProductionApplication instance.</p>
<p>This still doesn&#8217;t make code that is embedded inside servlets easy to unit test though, since you still need the servlet container. </p>
<p>I have never used the design I have just mentioned, so I am not sure if it has serious problems or not, but it would be easier to refactor to if someone is migrating an existing Servlet based application (easy enough that it seems like a free way to remove singleton dependencies that would be easier than replacing an existing apps use of servlets all together).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-2573</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Wed, 09 Dec 2009 14:43:26 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-2573</guid>
		<description>@trevor,

you may look at http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/ to see why servlets are a problem.</description>
		<content:encoded><![CDATA[<p>@trevor,</p>
<p>you may look at <a href="http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/" rel="nofollow">http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/</a> to see why servlets are a problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trevor</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-2572</link>
		<dc:creator>Trevor</dc:creator>
		<pubDate>Wed, 09 Dec 2009 10:37:52 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-2572</guid>
		<description>I am going to echo the issue brought up by Michael, and point out that the servlet will still need to access a global variable (or a singleton) to get the instance of RequestFactory.

For clarity&#039;s sake you should indicate this, since you cannot create the servlet via a modified constructor that takes a RequestFactory object.  So the overriding design principal, as stated, is broken at this one point in favor of a simpler approach.</description>
		<content:encoded><![CDATA[<p>I am going to echo the issue brought up by Michael, and point out that the servlet will still need to access a global variable (or a singleton) to get the instance of RequestFactory.</p>
<p>For clarity&#8217;s sake you should indicate this, since you cannot create the servlet via a modified constructor that takes a RequestFactory object.  So the overriding design principal, as stated, is broken at this one point in favor of a simpler approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-1189</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Fri, 12 Jun 2009 19:33:47 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-1189</guid>
		<description>@Manoj,

Your main should look like this:

class Main {
  public static void main(String...args) {
    AppFactory factory = new AppFactory(args);
    MyApp app = factory.create();
    app.run();
  }
}

Notice how the code is broken to three phases. Create factory, create app, run app. This makes it testable. No matter what your app, you should fallow this pattern. To got singletons to right places the Factory only creates a single instance and then passes that instance to the constructors of all classes as it calls new. See: http://misko.hevery.com/2009/03/30/collaborator-vs-the-factory/</description>
		<content:encoded><![CDATA[<p>@Manoj,</p>
<p>Your main should look like this:</p>
<p>class Main {<br />
  public static void main(String&#8230;args) {<br />
    AppFactory factory = new AppFactory(args);<br />
    MyApp app = factory.create();<br />
    app.run();<br />
  }<br />
}</p>
<p>Notice how the code is broken to three phases. Create factory, create app, run app. This makes it testable. No matter what your app, you should fallow this pattern. To got singletons to right places the Factory only creates a single instance and then passes that instance to the constructors of all classes as it calls new. See: <a href="http://misko.hevery.com/2009/03/30/collaborator-vs-the-factory/" rel="nofollow">http://misko.hevery.com/2009/03/30/collaborator-vs-the-factory/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manoj Mehta</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-1175</link>
		<dc:creator>Manoj Mehta</dc:creator>
		<pubDate>Mon, 08 Jun 2009 22:07:09 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-1175</guid>
		<description>Quick Question:&quot;The problem arises only when the singleton is available through a global “instance” variable as in Singleton.getInstance().&quot;If the Singleton classes don&#039;t expose a getInstance method, how do you propose that an instance of the ApplicationFactory is created by the main function of my application? Also, how does the ApplicationFactory instantiate the Singletons that it contains? Thanks,Manoj</description>
		<content:encoded><![CDATA[<p>Quick Question:&#8221;The problem arises only when the singleton is available through a global “instance” variable as in Singleton.getInstance().&#8221;If the Singleton classes don&#8217;t expose a getInstance method, how do you propose that an instance of the ApplicationFactory is created by the main function of my application? Also, how does the ApplicationFactory instantiate the Singletons that it contains? Thanks,Manoj</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giorgio Sironi</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-1144</link>
		<dc:creator>Giorgio Sironi</dc:creator>
		<pubDate>Sat, 30 May 2009 09:03:24 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-1144</guid>
		<description>No, because you must not use &#039;new&#039; operators in your business objects (everything is not a factory). But you can use &#039;new&#039; in tests.</description>
		<content:encoded><![CDATA[<p>No, because you must not use &#8216;new&#8217; operators in your business objects (everything is not a factory). But you can use &#8216;new&#8217; in tests.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dj_unforgetable</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-1052</link>
		<dc:creator>dj_unforgetable</dc:creator>
		<pubDate>Sun, 17 May 2009 14:59:36 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-1052</guid>
		<description>It&#039;s fine if I use the ApplicationFactory to get my object references, but I can easily break the singleton lifetime and instantiate a new Database, OfflineQueue, CreditCardProcessor and CreditCard myself, no ?</description>
		<content:encoded><![CDATA[<p>It&#8217;s fine if I use the ApplicationFactory to get my object references, but I can easily break the singleton lifetime and instantiate a new Database, OfflineQueue, CreditCardProcessor and CreditCard myself, no ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Another Architectural Framework, But Why? &#171; shaun smith</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-927</link>
		<dc:creator>Another Architectural Framework, But Why? &#171; shaun smith</dc:creator>
		<pubDate>Wed, 29 Apr 2009 12:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-927</guid>
		<description>[...] standard Singleton implementation (that static getInstance method) is severely flawed. Unless you are writing device drivers, there [...]</description>
		<content:encoded><![CDATA[<p>[...] standard Singleton implementation (that static getInstance method) is severely flawed. Unless you are writing device drivers, there [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AS3 Dependency Injection and [Autowire] &#171; shaun smith</title>
		<link>http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/comment-page-1/#comment-774</link>
		<dc:creator>AS3 Dependency Injection and [Autowire] &#171; shaun smith</dc:creator>
		<pubDate>Sat, 14 Mar 2009 18:47:10 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=181#comment-774</guid>
		<description>[...] you could use a Singleton to hang all your objects on. That would not be cool: link, link, [...]</description>
		<content:encoded><![CDATA[<p>[...] you could use a Singleton to hang all your objects on. That would not be cool: link, link, [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
