<?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: Solving problems you didn’t know you never had since 1995</title>
	<atom:link href="http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/feed/" rel="self" type="application/rss+xml" />
	<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/</link>
	<description>Musings and thoughts on programming and other geeky stuff</description>
	<lastBuildDate>Tue, 15 May 2012 08:42:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jalf</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-38160</link>
		<dc:creator>jalf</dc:creator>
		<pubDate>Tue, 15 May 2012 08:42:53 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-38160</guid>
		<description>&lt;p&gt;@Xander:
first, to be precise, I don&#039;t believe I ever said that globals are ever &lt;em&gt;necessary&lt;/em&gt;. I said that they may sometimes be convenient, or may even be the preferable solution. But not &lt;em&gt;necessary&lt;/em&gt;. :)&lt;/p&gt;

&lt;p&gt;And even when you think making an object global is a good idea, it often isn&#039;t.
Taking your resource manager as an example, why does it need to be global? The vast majority of your code shouldn&#039;t need to know about it. Pass it around to the few classes that do need it. Or perhaps even better, ask yourself why you need a resource manager &lt;em&gt;at all&lt;/em&gt;. &quot;Manager&quot; classes are always a warning sign. What does it mean to &quot;manage&quot; a resource? What kind of management does it need? Can&#039;t a resource take care of itself? What responsibilities does a &quot;manager&quot; have? Rename it, split it up into multiple smaller classes, or remove it entirely. And very likely, you&#039;ll find that there&#039;s no need to make it global either.&lt;/p&gt;

&lt;p&gt;You&#039;ll also find that it&#039;s not a true &quot;global&quot; in any case. It has a limited lifetime (it doesn&#039;t make sense to &quot;manage&quot; a Direct3D resource before your D3D Device has been created, or after it has been destroyed, for example).&lt;/p&gt;

&lt;p&gt;As to your main point, several points come to mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what would your proposed mutex do? Just ensure that calls to &lt;code&gt;instance()&lt;/code&gt; are serialized? That&#039;s only necessary at construction (and not even then, assuming a compiler which properly implements C++11&#039;s memory and threading models), and I would much rather just explicitly control the object&#039;s construction in any case (see below), making that problem go away entirely. So doing so really solves a non-problem. And it won&#039;t make the actual &quot;inner&quot; object instance thread-safe either. So I don&#039;t buy the &quot;safety&quot; thing. Is there some other safety benefit I&#039;m not seeing?&lt;/li&gt;
&lt;li&gt;I&#039;ve come to disagree with the &quot;order of construction&quot; argument. Most of the problems I&#039;ve encountered in the real world with singletons have been related precisely to order (and time and place) of construction: with a singleton, I simply have no clue when it&#039;s going to be initialized. That is often a problem, especially for objects you may want to parametrize (which file should your logger output to, for example? Presumably your resource manager needs to know about your OpenGL context or Direct3D device (Resource managers tend to imply people are making a game, in my experience :)). With singletons, passing such parameters isn&#039;t easy, &lt;em&gt;because you have no clear point at which it is instantiated&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if order of construction matters, that&#039;s a very strong reason to avoid making it global. Construct your objects explicitly, in &lt;code&gt;main&lt;/code&gt; or another function.&lt;/p&gt;

&lt;p&gt;Of course, if you absolutely want global&#039;ish access, you can create the object locally in &lt;code&gt;main&lt;/code&gt;, for example, and then set a global pointer to point to it. Then you still control order and time of construction, while also providing a means for code to access the object globally.&lt;/p&gt;

&lt;p&gt;But generally, my rule of thumb is that globals should not depend on order of construction (they shouldn&#039;t need to access other globals).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Xander:
first, to be precise, I don’t believe I ever said that globals are ever <em>necessary</em>. I said that they may sometimes be convenient, or may even be the preferable solution. But not <em>necessary</em>. :)</p>

<p>And even when you think making an object global is a good idea, it often isn’t.
Taking your resource manager as an example, why does it need to be global? The vast majority of your code shouldn’t need to know about it. Pass it around to the few classes that do need it. Or perhaps even better, ask yourself why you need a resource manager <em>at all</em>. “Manager” classes are always a warning sign. What does it mean to “manage” a resource? What kind of management does it need? Can’t a resource take care of itself? What responsibilities does a “manager” have? Rename it, split it up into multiple smaller classes, or remove it entirely. And very likely, you’ll find that there’s no need to make it global either.</p>

<p>You’ll also find that it’s not a true “global” in any case. It has a limited lifetime (it doesn’t make sense to “manage” a Direct3D resource before your D3D Device has been created, or after it has been destroyed, for example).</p>

<p>As to your main point, several points come to mind:</p>

<ul>
<li>what would your proposed mutex do? Just ensure that calls to <code>instance()</code> are serialized? That’s only necessary at construction (and not even then, assuming a compiler which properly implements C++11’s memory and threading models), and I would much rather just explicitly control the object’s construction in any case (see below), making that problem go away entirely. So doing so really solves a non-problem. And it won’t make the actual “inner” object instance thread-safe either. So I don’t buy the “safety” thing. Is there some other safety benefit I’m not seeing?</li>
<li>I’ve come to disagree with the “order of construction” argument. Most of the problems I’ve encountered in the real world with singletons have been related precisely to order (and time and place) of construction: with a singleton, I simply have no clue when it’s going to be initialized. That is often a problem, especially for objects you may want to parametrize (which file should your logger output to, for example? Presumably your resource manager needs to know about your OpenGL context or Direct3D device (Resource managers tend to imply people are making a game, in my experience :)). With singletons, passing such parameters isn’t easy, <em>because you have no clear point at which it is instantiated</em>.</li>
</ul>

<p>So if order of construction matters, that’s a very strong reason to avoid making it global. Construct your objects explicitly, in <code>main</code> or another function.</p>

<p>Of course, if you absolutely want global’ish access, you can create the object locally in <code>main</code>, for example, and then set a global pointer to point to it. Then you still control order and time of construction, while also providing a means for code to access the object globally.</p>

<p>But generally, my rule of thumb is that globals should not depend on order of construction (they shouldn’t need to access other globals).</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Xander</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-38006</link>
		<dc:creator>Xander</dc:creator>
		<pubDate>Sun, 13 May 2012 08:51:12 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-38006</guid>
		<description>&lt;p&gt;Very interesting article: you have [i]almost[/i] talked me out of using a singleton-like design for the Log and ResourceManager I am working on.&lt;/p&gt;

&lt;p&gt;You say yourself that sometimes global variables are necessary, but there is no need to impose the single instance rule. I certainly agree with this.&lt;/p&gt;

&lt;p&gt;However, suppose you have a template [i]class Singleton[/i] which provides a singleton-like design pattern for [i]class T[/i]. To me, this seems to provide a safer global access than a plain global (because one can fairly easily add inbuilt mutexes etc. and one doesn&#039;t have order of construction problems). On the other hand, because the Singleton design is implemented in its own template class, it doesn&#039;t actually prevent other instances being created.&lt;/p&gt;

&lt;p&gt;What do you think of this approach? Perhaps it would be clearer to rename [i]Singleton[/i] to [i]Global[/i], but that name could be somewhat confusing too (since only one object of that type can be instantiated). However, it seems to me that this essentially matches your criteria (imposes globality, which is sometimes desirable, but not strictly single instantiation), but in a safer manner than a normal global variable.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Very interesting article: you have [i]almost[/i] talked me out of using a singleton-like design for the Log and ResourceManager I am working on.</p>

<p>You say yourself that sometimes global variables are necessary, but there is no need to impose the single instance rule. I certainly agree with this.</p>

<p>However, suppose you have a template [i]class Singleton[/i] which provides a singleton-like design pattern for [i]class T[/i]. To me, this seems to provide a safer global access than a plain global (because one can fairly easily add inbuilt mutexes etc. and one doesn’t have order of construction problems). On the other hand, because the Singleton design is implemented in its own template class, it doesn’t actually prevent other instances being created.</p>

<p>What do you think of this approach? Perhaps it would be clearer to rename [i]Singleton[/i] to [i]Global[/i], but that name could be somewhat confusing too (since only one object of that type can be instantiated). However, it seems to me that this essentially matches your criteria (imposes globality, which is sometimes desirable, but not strictly single instantiation), but in a safer manner than a normal global variable.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Yarin</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-32792</link>
		<dc:creator>Yarin</dc:creator>
		<pubDate>Sun, 25 Mar 2012 03:09:07 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-32792</guid>
		<description>&lt;p&gt;Thanks for a great article. I&#039;ve been muddling through the singleton debate for a long time- this article cleared the fog. Done with them. Keep writing.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for a great article. I’ve been muddling through the singleton debate for a long time– this article cleared the fog. Done with them. Keep writing.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Global Varibles - Page 7</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-30268</link>
		<dc:creator>Global Varibles - Page 7</dc:creator>
		<pubDate>Tue, 06 Mar 2012 23:34:27 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-30268</guid>
		<description>&lt;p&gt;[...]  [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[…]  […]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Hari Karam Singh</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-17597</link>
		<dc:creator>Hari Karam Singh</dc:creator>
		<pubDate>Sat, 19 Nov 2011 16:10:07 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-17597</guid>
		<description>&lt;p&gt;Hidden in the sense that the lowest level object which is making the call now has 2 more dependencies in addition to its dependency on the settings class - perhaps not hidden from it&#039;s perspective but from the top level vantage point, doesn&#039;t the dependency on Settings seem quite buried?  Say you changed the structure of the settings object and needed to find all referencing code...&lt;/p&gt;

&lt;p&gt;At first I was inclined toward your stance on using a simple global variable which is init&#039;ed perhaps, with the app startup.  Upon reflection however, I&#039;m not sure I see the difference between this and the singleton pattern, other than that the later packages the global variable (as a static) and has a self contained initialisation.  Some might even argue that this is more in keeping with Single Responsibility Principle.  What do you think?&lt;/p&gt;

&lt;p&gt;Thanks for the thought provoking and detailed discussion by the way.  It&#039;s very pertinent to the code I&#039;m writing as we speak :)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hidden in the sense that the lowest level object which is making the call now has 2 more dependencies in addition to its dependency on the settings class — perhaps not hidden from it’s perspective but from the top level vantage point, doesn’t the dependency on Settings seem quite buried?  Say you changed the structure of the settings object and needed to find all referencing code…</p>

<p>At first I was inclined toward your stance on using a simple global variable which is init’ed perhaps, with the app startup.  Upon reflection however, I’m not sure I see the difference between this and the singleton pattern, other than that the later packages the global variable (as a static) and has a self contained initialisation.  Some might even argue that this is more in keeping with Single Responsibility Principle.  What do you think?</p>

<p>Thanks for the thought provoking and detailed discussion by the way.  It’s very pertinent to the code I’m writing as we speak :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: jalf</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-17474</link>
		<dc:creator>jalf</dc:creator>
		<pubDate>Thu, 17 Nov 2011 19:27:32 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-17474</guid>
		<description>&lt;p&gt;How is the first one a hidden dependency? It&#039;s clear exactly &lt;em&gt;how&lt;/em&gt; the current object retrieves the settings object. We know that it does this through its reference to the parent controller, which has a reference to the parent application, and so on. We have explicitly said in the code that this code requires a reference to the parent controller, so it is not a hidden dependency. I can look at the object&#039;s constructor and see that it takes a reference to the object it needs to reference.
Or I can follow the code the other way around: Start at wherever the &lt;code&gt;settings&lt;/code&gt; object is created, and then read along to see where it is passed to. If I follow the code from that point, it naturally takes me to every use site.&lt;/p&gt;

&lt;p&gt;On the other hand, in your second snippet, it&#039;s not clear where this settings object &lt;em&gt;comes from&lt;/em&gt;. And I can&#039;t follow the uses of the object. If I start at the construction of the &lt;code&gt;settings&lt;/code&gt; object, I immediately run into &quot;it&#039;s stored into a singleton, which is... just there. At some point, someone might call &lt;code&gt;getInstance&lt;/code&gt; on it, but I don&#039;t know who does that, or when or why.&lt;/p&gt;

&lt;p&gt;So I disagree with your analysis of dependencies.&lt;/p&gt;

&lt;p&gt;On the other hand, it is certainly more &lt;em&gt;convenient&lt;/em&gt; to just make the settings object globally accessible.&lt;/p&gt;

&lt;p&gt;So go ahead and do that. But it doesn&#039;t need to be a &lt;em&gt;singleton&lt;/em&gt; to achieve that goal. Just a single global/static instance will allow everyone to access the settings object if they want to. There&#039;s no need for messing around with singletons and all the &lt;em&gt;other&lt;/em&gt; problems they cause.&lt;/p&gt;

&lt;p&gt;Singletons are global, but globals are not singletons. If you need a global, that doesn&#039;t mean you have to use a singleton.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>How is the first one a hidden dependency? It’s clear exactly <em>how</em> the current object retrieves the settings object. We know that it does this through its reference to the parent controller, which has a reference to the parent application, and so on. We have explicitly said in the code that this code requires a reference to the parent controller, so it is not a hidden dependency. I can look at the object’s constructor and see that it takes a reference to the object it needs to reference.
Or I can follow the code the other way around: Start at wherever the <code>settings</code> object is created, and then read along to see where it is passed to. If I follow the code from that point, it naturally takes me to every use site.</p>

<p>On the other hand, in your second snippet, it’s not clear where this settings object <em>comes from</em>. And I can’t follow the uses of the object. If I start at the construction of the <code>settings</code> object, I immediately run into “it’s stored into a singleton, which is… just there. At some point, someone might call <code>getInstance</code> on it, but I don’t know who does that, or when or why.</p>

<p>So I disagree with your analysis of dependencies.</p>

<p>On the other hand, it is certainly more <em>convenient</em> to just make the settings object globally accessible.</p>

<p>So go ahead and do that. But it doesn’t need to be a <em>singleton</em> to achieve that goal. Just a single global/static instance will allow everyone to access the settings object if they want to. There’s no need for messing around with singletons and all the <em>other</em> problems they cause.</p>

<p>Singletons are global, but globals are not singletons. If you need a global, that doesn’t mean you have to use a singleton.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Hari Karam Singh</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-17460</link>
		<dc:creator>Hari Karam Singh</dc:creator>
		<pubDate>Thu, 17 Nov 2011 15:01:17 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-17460</guid>
		<description>&lt;p&gt;So say you need access to a Settings class at various hierarchical levels in your code, for instance the Application, the Controller and the View.  You could have a globally accessible Singleton and have code like:&lt;/p&gt;

&lt;blockquote&gt;
SettingsClass.getSetting(&#039;showTooltips&#039;)
&lt;/blockquote&gt;

&lt;p&gt;Or you have it be an instance var on the Application class which is referenced by an instance var on the Controller class which is referenced by an instance var on the view and so on...  You end up with the following:&lt;/p&gt;

&lt;blockquote&gt;
self.parentController.parentApplication.settings.getSetting(&#039;showTooltips&#039;);
&lt;/blockquote&gt;

&lt;p&gt;Which is a (very!) hidden dependency.  Or you do...&lt;/p&gt;

&lt;blockquote&gt;
Application&#039;s init:
self.viewController.showTooltips = settings.getSettings(&#039;showTooltips&#039;)

viewController&#039;s init:
self.view = this.showTooltips

&lt;/blockquote&gt;

&lt;p&gt;...and create tons of code with a multiplicity of by way of property names, making changes such as refactoring a serious sweat.&lt;/p&gt;

&lt;p&gt;What I&#039;m asking really, is what about the case for the singleton (or at least a global variable) where it reduces complexity for application areas which aren&#039;t resource intensive?&lt;/p&gt;

&lt;p&gt;Like many things in programming isn&#039;t it a trade off between simplicity and covering all potential future  cases?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>So say you need access to a Settings class at various hierarchical levels in your code, for instance the Application, the Controller and the View.  You could have a globally accessible Singleton and have code like:</p>

<blockquote>
SettingsClass.getSetting(‘showTooltips’)
</blockquote>

<p>Or you have it be an instance var on the Application class which is referenced by an instance var on the Controller class which is referenced by an instance var on the view and so on…  You end up with the following:</p>

<blockquote>
self.parentController.parentApplication.settings.getSetting(‘showTooltips’);
</blockquote>

<p>Which is a (very!) hidden dependency.  Or you do…</p>

<blockquote>
Application’s init:
self.viewController.showTooltips = settings.getSettings(‘showTooltips’)

viewController’s init:
self.view = this.showTooltips

</blockquote>

<p>…and create tons of code with a multiplicity of by way of property names, making changes such as refactoring a serious sweat.</p>

<p>What I’m asking really, is what about the case for the singleton (or at least a global variable) where it reduces complexity for application areas which aren’t resource intensive?</p>

<p>Like many things in programming isn’t it a trade off between simplicity and covering all potential future  cases?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: jalf</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-14750</link>
		<dc:creator>jalf</dc:creator>
		<pubDate>Sat, 29 Oct 2011 12:18:41 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-14750</guid>
		<description>&lt;p&gt;@Adriano: Why do you need to &quot;avoid&quot; having multiple instances of an object?
I don&#039;t need to do anything to &quot;avoid&quot; jumping into the sea. I don&#039;t need to do anything to &quot;avoid&quot; buying a plane ticket. Those things only happen if I &lt;em&gt;decide&lt;/em&gt; to do them. And likewise, instances of an object only exist if I decide to create them. If I only need one instance of an object, why would I create two? Why do you feel that you need to do anything special to &quot;avoid&quot; creating multiple instances?&lt;/p&gt;

&lt;p&gt;The second part, about global access, is somewhat more subjective. Perhaps you really want &lt;em&gt;global&lt;/em&gt; access to this object. In that case, go ahead and make it global. I think global access is nearly always the wrong thing, but it really doesn&#039;t matter. If you want global access, use a global. If you don&#039;t want global access, don&#039;t make it a global. Neither case requires a singleton.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;I also think you can solve the prob­lem get­ting those depen­den­cies vis­i­ble. Don’t you think you can assign a sin­gle­ton instance to a mem­ber vari­able of a class that needs it&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sure, you can do that. But then (1) why does it need to be a singleton, why does it need to be globally accessible, and (2) you still have no way to ensure that it&#039;s never used in the &quot;other&quot; way. That&#039;s what&#039;s icky about singletons. You don&#039;t &lt;em&gt;know&lt;/em&gt; if these hidden dependencies exist. They &lt;em&gt;might&lt;/em&gt; all be made explicit as you expect, but there might also be a number of&quot;hidden&quot; uses scattered around your code. You don&#039;t know.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Adriano: Why do you need to “avoid” having multiple instances of an object?
I don’t need to do anything to “avoid” jumping into the sea. I don’t need to do anything to “avoid” buying a plane ticket. Those things only happen if I <em>decide</em> to do them. And likewise, instances of an object only exist if I decide to create them. If I only need one instance of an object, why would I create two? Why do you feel that you need to do anything special to “avoid” creating multiple instances?</p>

<p>The second part, about global access, is somewhat more subjective. Perhaps you really want <em>global</em> access to this object. In that case, go ahead and make it global. I think global access is nearly always the wrong thing, but it really doesn’t matter. If you want global access, use a global. If you don’t want global access, don’t make it a global. Neither case requires a singleton.</p>

<blockquote>
  <p>I also think you can solve the prob­lem get­ting those depen­den­cies vis­i­ble. Don’t you think you can assign a sin­gle­ton instance to a mem­ber vari­able of a class that needs it</p>
</blockquote>

<p>Sure, you can do that. But then (1) why does it need to be a singleton, why does it need to be globally accessible, and (2) you still have no way to ensure that it’s never used in the “other” way. That’s what’s icky about singletons. You don’t <em>know</em> if these hidden dependencies exist. They <em>might</em> all be made explicit as you expect, but there might also be a number of“hidden” uses scattered around your code. You don’t know.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Adriano Di Giovanni</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-12390</link>
		<dc:creator>Adriano Di Giovanni</dc:creator>
		<pubDate>Wed, 05 Oct 2011 11:22:38 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-12390</guid>
		<description>&lt;p&gt;I started studying OOP less than a year ago. So, it is not difficult that all of you are more aware of it than me.&lt;/p&gt;

&lt;p&gt;IMHO, I think it is not a bad idea to use Singletons in order to avoid having multiple instances of an object (i.e. the Model) and have a global access to the single instance.&lt;/p&gt;

&lt;p&gt;I agree with you about the fact that Singletons increase hidden dependencies. But I also think you can solve the problem getting those dependencies visible. Don&#039;t you think you can assign a singleton instance to a member variable of a class that needs it?&lt;/p&gt;

&lt;p&gt;Doing so, you make the dependency visible and give yourself the opportunity to remove the single instance constraint if you made a bad assumption about it.&lt;/p&gt;

&lt;p&gt;Does it make sense?
Do I have to apologize for my english? :)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I started studying OOP less than a year ago. So, it is not difficult that all of you are more aware of it than me.</p>

<p>IMHO, I think it is not a bad idea to use Singletons in order to avoid having multiple instances of an object (i.e. the Model) and have a global access to the single instance.</p>

<p>I agree with you about the fact that Singletons increase hidden dependencies. But I also think you can solve the problem getting those dependencies visible. Don’t you think you can assign a singleton instance to a member variable of a class that needs it?</p>

<p>Doing so, you make the dependency visible and give yourself the opportunity to remove the single instance constraint if you made a bad assumption about it.</p>

<p>Does it make sense?
Do I have to apologize for my english? :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dieter Govaerts</title>
		<link>http://jalf.dk/blog/2010/03/singletons-solving-problems-you-didnt-know-you-never-had-since-1995/comment-page-1/#comment-4984</link>
		<dc:creator>Dieter Govaerts</dc:creator>
		<pubDate>Tue, 08 Mar 2011 12:05:44 +0000</pubDate>
		<guid isPermaLink="false">http://jalf.dk/blog/?p=532#comment-4984</guid>
		<description>&lt;p&gt;Thanks for sharing this. You definitely have a point and I will consider never to use a Singleton again.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for sharing this. You definitely have a point and I will consider never to use a Singleton again.</p>]]></content:encoded>
	</item>
</channel>
</rss>

