top | item 42998407

(no title)

chikere232 | 1 year ago

Singletons are just globals for people who have learnt "globals are bad" but lack a deeper understanding

discuss

order

Salgat|1 year ago

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.