Singleton really use them. I would generalize their usefulness as:
"A singleton should be used to represent an object, in accordance with the fundamental design or requirements, there can be no more than one instance, and there is data or resources associated with the object that carries a measurable cost." Here is what I mean.
1) You should not use Singleton in the case when there is a lot of something, but we are only interested in one. If there can be two on the system, create the instance explicitly.
2) Many applications of Singleton can be replaced by a class with all static methods and data. If you can do it without a performance penalty, do it.
3) You should consider Singleton if there is a noticeable cost for setting up the object: for example, if it is a physical resource that needs to be initialized, or if it relies on some lookup table that needs to be initialized. If so, using Singleton you can defer initialization costs until the first use of the object, while a static class will usually be initialized when the application starts. If the object is never used, you never pay for initialization.
DJClayworth Jan 21 '09 at 10:15 2009-01-21 22:15
source share