<story><title>So Singletons are bad, then what?</title><url>http://programmers.stackexchange.com/questions/40373/so-singletons-are-bad-then-what</url></story><parent_chain></parent_chain><comment><author>shitgoose</author><text>Hilarious! Doing x=C.getX() is bad, but if it is hidden by numerous layers of libraries and monstrous config files, somehow it becomes acceptable. Out of site, out of mind. The fact that global scope bean is essentially a singleton, doesn&amp;#x27;t seem to bother architecturally inclined crowd - they are too busy admiring sound of their own voice pronouncing words &amp;quot;dependency injection&amp;quot;, &amp;quot;mutability&amp;quot; and &amp;quot;coupling&amp;quot;.&lt;p&gt;The top answer is a perfect example of what is wrong with IT today. It takes a working solution, declares it wrong and starts piling up classes and interfaces to solve a problem, that was never a problem in first place (OP never said that their singleton-based cache didn&amp;#x27;t work, he merely asked if there are &amp;quot;better&amp;quot; ways of doing it). So in the end we have the same singleton cache, but hidden behind interfaces (&amp;quot;It makes the code easier to read&amp;quot; - yea, right, easier, my ass! Ctrl+click on interface method and try to read the code),  thousand lines xml Spring configs, and other crap that is completely irrelevant, hard to follow and debug, but glamorous enough for SOA boys to spend endless hours talking about it.</text></comment>
<story><title>So Singletons are bad, then what?</title><url>http://programmers.stackexchange.com/questions/40373/so-singletons-are-bad-then-what</url></story><parent_chain></parent_chain><comment><author>Pxtl</author><text>I always get cranky about people fixating on the difference between a static class and a singleton.  A static class is just your language&amp;#x27;s default implementation of the singleton pattern, it just fails at providing any polymorphism to swap out the object for a new one.  Mechanically, they do the same thing.  Single global point of access to some effectively-global-state.&lt;p&gt;Also, the singleton thing (and interfaces everywhere) stinks of YAGNI.  Your toolkit can find all references to X.Y, which means you can replace all references to X with a reference to X.Instance.Y.  &lt;i&gt;when&lt;/i&gt; you need to change a static class to a singleton, do so.&lt;p&gt;Or just use a dynamic language where there isn&amp;#x27;t any difference.  Seriously, I wish C# offered a &amp;quot;root&amp;quot; static class or global variables or something equivalent so that the singleton pattern was less verbose to implement, because you &lt;i&gt;will&lt;/i&gt; need them.</text></comment>