News for hackers. Stuff that matters.
Re:Singleton Is a Bad Idea by moron4hire on Sunday April 10, 2022 @02:57PM (#30980454)
Except these two things--single instance-ness of classes and private-ness of class fields--are not comparable things. There's no way to easily change a field from public to private without breaking an unbounded set of code. The Singleton pattern is similarly difficult to change the lifetime of an object without breaking code. But we can achieve the same, desired results of Singleton with Dependency Injection, which can change the lifetime of an object without breaking dependent code. We have no such alternative for field access modifiers.

Yes, these things are tools, and in some cases, better tools have been invented.

There are no comments on this comment yet.