2 ms·
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 fr
by moron4hire 5y ago
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.