Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi all,

i'm new to Singleton design pattern, if can ANYONE EXPLAINS or quick understanding of what is Singleton design pattern and how should i use for simple web application or anything.

What I have tried:

Tried with ONLINE EXAMPLE but did not understood
Posted
Updated 25-Apr-18 11:25am

The idea of a singleton is very simple: it's a class with a private constructor, so it cannot be instantiated form outside the class. This means that the class is absolutely in control of how many instances of the class are created, and when they are created. A singleton class creates a single instance of itself, which it returns to calling classes that need to access it via a specific method for that purpose.

Personally, I think of them as a glorified global variable which kinda breaks the whole OOPs paradigm, and don't use them - but I have seen them used well for single-resource systems where there is one hardware object which needs to be used sensibly by multiple classes and /or threads.

Generally considered an anathema these days ...
 
Share this answer
 
Comments
Maciej Los 25-Apr-18 17:29pm    
5ed!
I would start form its very Wikipedia page: Singleton pattern - Wikipedia[^].
 
Share this answer
 
Comments
Maciej Los 25-Apr-18 17:29pm    
5ed!
CPallini 26-Apr-18 9:34am    
Thank you, Maciej.

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