2015年4月14日星期二

NetTuts.com: Design Patterns: The Singleton Pattern


On the NetTuts.com site today they've posted another in their series introducing the various design patterns that have been established in software development. In this new post they talk about the Singleton pattern (or "anti-pattern" as it's sometimes called).



In this article you are going to learn how to implement the Singleton design pattern, and why and when to use this pattern in your application. As the name "Singleton" suggests, this method allows us to create one and only one object of a class.


They start with a basic definition of the pattern that, at its heart, is about reusing one and only one instance of an object. To help make it more concrete, they include an example that's refactored to use the Singleton pattern: creating and reusing single instances of database connections (PDO). The article also talks a bit about the idea of the Singleton being an anti-pattern and how it can make things like unit testing difficult.


Link: http://code.tutsplus.com/tutorials/design-patterns-the-singleton-pattern--cms-23073

没有评论:

发表评论