Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created January 15, 2014 03:08
Show Gist options
  • Save GaryJones/8430080 to your computer and use it in GitHub Desktop.
Save GaryJones/8430080 to your computer and use it in GitHub Desktop.
References for Why Not to Use Singleton Design Pattern
http://www.youtube.com/watch?v=-FRm3VPhseI Google's Clean Code Talks
http://blog.gordon-oheim.biz/2011-01-17-Why-Singletons-have-no-use-in-PHP/
http://sebastian-bergmann.de/archives/882-Testing-Code-That-Uses-Singletons.html
http://eamann.com/tech/making-singletons-safe-in-php/
http://hakre.wordpress.com/2012/06/10/the-missing-patterns-of-the-php-manual/#p2
http://blogs.msdn.com/b/scottdensmore/archive/2004/05/25/140827.aspx
http://www.phptherightway.com/pages/Design-Patterns.html ("You should be wary when using the singleton pattern, as by its very nature it introduces global state into your application, reducing testability.")
http://www.practicaldesignpatternsinphp.com/ ("The Singleton Pattern is perhaps the most well known - and most often misused - pattern in all of PHP design pattern development. Its simplicity, combined with its seeming benefits makes it a widely-used (and overused) pattern. The Singleton is not so much a recommended pattern, as a pattern I recommend you shy away from.")
http://www.slideshare.net/go_oh/singletons-in-php-why-they-are-bad-and-how-you-can-eliminate-them-from-your-applications
http://en.wikipedia.org/wiki/Singleton_pattern
http://i.stack.imgur.com/Dzdio.png
Once you've read all those, read everything abou Dependency Injection, how that helps with injecting mocks during unit testing, and therefore why Singletons are bad.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment