Total Posts:1|Showing Posts:1-1
OOP Singletons are an anti-pattern.
Add as Friend
Challenge to a Debate
Send a Message
3/21/2015 1:03:33 AM
Posted: 2 years ago
The Singleton pattern in object orientated programing, I consider an anti-pattern. Systems today, and for the near future, will be using more parallel computing and run across a network on different platforms.
The Open-closed principle: open for extension, closed for modification. Has lead to the advice that Global variables be avoided in all cases because the variable is not protected from modification by other objects.
This pattern was created to solve the problem of needing one instantiation of an object that controls concurrent access to a shared resource from multiple parts.
However, this pattern causes problems. When the class is referenced, it searches for an instance of a singleton object. If no object is found it creates a singleton object.
This essentially is to make a global variable protected from modification. But in the fast-paced, multi-noded environment we are working in today, it's possible for 2 or more objects to be created and no way of reconciling them.
The use of a command pattern and a factory pattern seems the best solution to control the number of instances, queue requests, and redirect requests to a single object.
Also singleton are lazily implemented...
I think this is a rather open-shut case. But just curious if there is anyone who will debate good coding practices.