|
|
|
|
|
by pornel
5697 days ago
|
|
Singletons don't solve problem of global variables, they are global themselves. They are global shared state than can be unexpectedly accessed from any place in the program. Encapsulation provided by singletons makes them even more problematic than global variables. You can temporarily overwrite global variable, run function that uses it, and restore global value. Singletons can be designed to prevent that, which kills testability of code that uses singletons (e.g. when you need to replace global DB connection with mock object). |
|