Timeline for The Singleton Pattern
Current License: CC BY-SA 2.5
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 17, 2011 at 13:27 | comment | added | red-dirt | You might also examine some large open source "C" based projects for a solid example of how to handle logging etc w/o a singleton pattern. Apache, for one. Even in an OOP system, if you litter your code with what is basically a global object, then you are tightly coupling your code (bad OOP) and making unit testing a nightmare. | |
| Jan 16, 2011 at 21:38 | comment | added | Winston Ewert | Stateless singletons are fine. The problem is that many singletons are "cheap lipstick" on mutable global variables. The only problem, (that I'm aware of) with stateless singletons is that they can be difficult to unit test. In some cases I want to replace the singleton with a mock implementation for a test. Of course, if that's the case its probably not a stateless singleton. | |
| Jan 16, 2011 at 21:25 | comment | added | Slawek | Sure, so i don't know what is the problem with stateless singletons :) | |
| Jan 16, 2011 at 21:00 | comment | added | Winston Ewert | Regarding Math, that's not a singleton its a static class. There is no problem with static/global functions as long as those functions as long as they are stateless. | |
| Jan 16, 2011 at 20:58 | comment | added | Winston Ewert | Regarding logging, thats a case where the coupling is much less of a problem. Most objects have back-and-forth in terms of interaction with the rest of the system. But logging only has data sent in one direction (the log) so the coupling is not really a problem there. As a result using singletons/global variables/whatever technique doesn't cause so many problems. | |
| Jan 16, 2011 at 20:55 | comment | added | Winston Ewert | Singletons only fix small problems with global variables. Global variables encourage coupling which ideally we'd like to prevent. The technique of using singletons does nothing to help there. The complaint against singletons is basically that people convert a global variable into a singleton and think all is good. But really they've only fixed relatively minor issues that come from using globals. | |
| Jan 16, 2011 at 20:24 | comment | added | Slawek | Hm... singleton is a concept or something you can use and singleton pattern is how you'll make that concept work. | |
| Jan 16, 2011 at 20:19 | comment | added | Michael K | 'Singletons are good design practice because you can always modify global object somewhere, or someone else can just overwrite it. Not possible with singleton pattern.' ?? Could you clarify the difference between 'singleton' and 'singleton pattern'? | |
| Jan 16, 2011 at 19:53 | history | edited | Slawek | CC BY-SA 2.5 | added 91 characters in body |
| Jan 16, 2011 at 19:47 | history | answered | Slawek | CC BY-SA 2.5 |