News for hackers. Stuff that matters.
Re:Singleton Is a Bad Idea by strictfp on Sunday April 10, 2022 @03:10PM (#30980587)
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.
Re:Singleton Is a Bad Idea by mdb31 on Sunday April 10, 2022 @03:15PM (#30980644)
Sure, 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!

Re:Singleton Is a Bad Idea by kjeetgill on Sunday April 10, 2022 @03:42PM (#30980932)
I 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.