3 ms·
> ...requiring/expectinv only one instance of a class to be available is obviously not an anti-pattern. I'll disagree. There are very few situations where rest
by humanrebar 5y ago
> ...requiring/expectinv only one instance of a class to be available is obviously not an anti-pattern.
I'll disagree. There are very few situations where restricting class instantiation to one object both solves a problem and doesn't cause unneeded headaches.
Almost always a boring global with careful access control is better. It provides a single object just as well without limiting options for future software engineering needs: testing, adding construction parameters, migration, gradual deprecation, etc.
As to legitimate uses, anything with system scope can't be controlled within a process. And there are few things that inherently couldn't be instantiated twice that aren't better managed by the OS.
- nsonha 5y ago> a boring global with careful access control There is no such thing as "access control to global", unless you mean humans in code review, in that case, OK
- humanrebar 5y agoYou can have global linkage and private access control in several ways.