Hacker News new | ask | show | jobs
by chikere232 487 days ago
Singletons are just globals for people who have learnt "globals are bad" but lack a deeper understanding
1 comments

Not 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.