<?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: Actionscript3 Design Patterns:The Singleton</title>
	<atom:link href="http://blog.eamonnfaherty.co.uk/2009/11/09/actionscript3-design-patternsthe-singleton/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.eamonnfaherty.co.uk/2009/11/09/actionscript3-design-patternsthe-singleton/</link>
	<description>technology enthusiast and public speaker</description>
	<lastBuildDate>Mon, 13 Jun 2011 21:57:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: eamonn</title>
		<link>http://blog.eamonnfaherty.co.uk/2009/11/09/actionscript3-design-patternsthe-singleton/comment-page-1/#comment-30</link>
		<dc:creator>eamonn</dc:creator>
		<pubDate>Tue, 10 Nov 2009 22:22:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.eamonnfaherty.co.uk/?p=234#comment-30</guid>
		<description>For me, the singleton has two main flaws.  The classes that use the singleton are tightly coupled to the implementation of the pattern and refactoring a singleton into something else is not trivial.  The effects of these criticisms can be eased:
Your singleton should implement an interface and all classes that use its public methods should do so using the interface type.  This means that you can change the getInstance method call to be another singleton, or something else, and so long as the replacement class implements the same interface you will not have to change any other code.
&lt;pre class=&quot;brush:as3&quot;&gt;
var socket : ISocketManager = SocketManagerSingleton.getInstace();
socket.connect();&lt;/pre&gt;
‚Ä¢	You should not use getInstance more than once.  Every time you use getInstance you are tightly coupling that method/class to the singleton.  Just because the singleton is a singleton it does not mean you cannot pass a reference of the object around.
&lt;pre class=&quot;brush:as3&quot;&gt;var applicationController:Controller = new Controller(SocketManagerSingleton.getInstace());&lt;/pre&gt;
Above I am passing a reference into my Controller instead of it getting the reference itself.  This means that my Controller does not know about the singleton so changing it means that I should not have to change my Controller.</description>
		<content:encoded><![CDATA[<p>For me, the singleton has two main flaws.  The classes that use the singleton are tightly coupled to the implementation of the pattern and refactoring a singleton into something else is not trivial.  The effects of these criticisms can be eased:<br />
Your singleton should implement an interface and all classes that use its public methods should do so using the interface type.  This means that you can change the getInstance method call to be another singleton, or something else, and so long as the replacement class implements the same interface you will not have to change any other code.</p>
<pre class="brush:as3">
var socket : ISocketManager = SocketManagerSingleton.getInstace();
socket.connect();</pre>
<p>‚Ä¢	You should not use getInstance more than once.  Every time you use getInstance you are tightly coupling that method/class to the singleton.  Just because the singleton is a singleton it does not mean you cannot pass a reference of the object around.</p>
<pre class="brush:as3">var applicationController:Controller = new Controller(SocketManagerSingleton.getInstace());</pre>
<p>Above I am passing a reference into my Controller instead of it getting the reference itself.  This means that my Controller does not know about the singleton so changing it means that I should not have to change my Controller.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

