5 ms·
Singletons are just globals for people who have learnt "globals are bad" but lack a deeper understanding
by chikere232 2y ago
Singletons are just globals for people who have learnt "globals are bad" but lack a deeper understanding
- Salgat 2y agoNot exactly. For example, you can have a singleton object that maintains a persistent connection to a db to persist logs to. No one's going to inject the "ElasticsearchLogger" object in their method/class by accident, and even then, they'll only have access to the singleton state that the class lets them have access to. So now your private Counter variable is inside a global singleton without being accessible by anyone, even if that person is disregarding all of OP's rules.