3 ms·
If you construct an object once, then what is the difference between that and a singleton? The answer is scope. Singletons exist explicitly for the purpose of
by hayst4ck 1y ago
If you construct an object once, then what is the difference between that and a singleton?
The answer is scope. Singletons exist explicitly for the purpose of violating scoping for the convenience of not having to thread that dependency through constructors.
https://testing.googleblog.com/2008/08/root-cause-of-singletons.html https://testing.googleblog.com/2008/08/root-cause-of-singlet...
- almostdeadguy 1y agoCalling these "singletons" maybe created confusion here, I'm more talking about singleton in the sense of a value that is created once and shared (i.e. injecting a value as a "Singleton" via something like Guice). I'm not arguing that you need to have values in global scope, I'm arguing that parameterless constructors prevent you from using shared values (actually _unless_ you have singletons in global scope).