Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to pattern approach.Is good approach to create Singleton pattern for all class?
Posted
Comments
[no name] 26-Oct-14 11:50am    
NO
Ravi Bhavnani 26-Oct-14 12:16pm    
Would you want all the tools in your toolbox to be hammers? The answer to that question is the same as the answer to your question.

/ravi
Naser Hassan 26-Oct-14 16:46pm    
It depends what you want to achieve with that class.
But before designing any class you need to keep one thing in mind that is SOLID principal .your first goal should be meeting SOLID then search for any pattern.
and whether all class should have singleton are not then Ravi has commented beautifully
mn.sathish 27-Oct-14 13:39pm    
Thanks a lot to all

No, of course.
The Singleton design pattern has its uses.
From the very Wikipedia[^] page:

the singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system.


Rougly speaking, if you need multiple instances of a class, then the Singleton is useless.
 
Share this answer
 
A big No. There is no one size fits all.

A Singleton candidate must satisfy three requirements:
1.) controls concurrent access to a shared resource.
2.) access to the resource will be requested from multiple, disparate parts of the system.
3.) there can be only one object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900