3 ms·
Having one instance of a class that's being passed around isn't bad. The singleton pattern with what's effectively a global variable , accessible from anywhere,
by strictfp 4y ago
Having one instance of a class that's being passed around isn't bad. The singleton pattern with what's effectively a global variable , accessible from anywhere, is bad though.
- mdb31 4y agoSure, as I said "a single static class: don't do that" -- however, the definition of a singleton, as per the GoF, is just "something that restricts the instantiation of a class to one instance". Nothing about global visibility, and again, any decent dependency-injection framework should manage that well enough. So, still mystified about all the singleton-hate here!
- kjeetgill 4y agoI mean, you're right. I came to much the same pattern myself. Much of the singleton hate is from everyone who hasn't figured out, seen, or works with a language that doesn't support "the good way" to do singletons. Alternatively, you could say this _similar, but different_ approach correctly acknowledges and similarly avoids _actual_ problematic singletons. We can all be friends here :D.