3 ms·
Not All Singletons are Evil
- dkersten 16y agoSingletons are good when both of the following features are required: 1. Global access is needed 2. Only a single instance is allowed If you don't need both of those, don't use a singleton. If you only need one instance, but there is no important reason to force the limitation of one instance, then don't use a singleton: simply instantiate your class only once. Don't place limitations because you don't need something right now (you may want a second logging system in the future, for example). People don't accidentally make two if statements when they wanted one - you won't accidentally instantiate a second object where you need just one. So, while you can mitigate the reasons people often say singletons are evil, this is still not a good reason to use them, unless you do, in fact, require both of the properties of singletons.