Back to list
Views:   79.2K
Replies:  1

Singleton usage examples?

Can anyone summarize when and where one would (and would not) use Singletons?
I am asking because it is said that programmers are overusing Singletons....
Walt Lynton, Mar 11, 2010
Reply 1
Normally i don't use the word single instance throughout the whole application. I rather prefer saying context. For example recently in another post i gave example of Shopping basket per user. Multiple baskets but just one basket per user. The same instance will be returned against the same user. Many people may scream at this definition ;)

Now why overusing ?
First it's very easy to implement. Secondly, being a single instance, it's very easy to be synchronized in mutltithreaded application. Thirdly it solves the toughest of the problem ---- State management in stateless environments.
Consider the same cart being returned for the same user, having the items stored in it, across multiple pages.

There can be many other perspectives to look at this, hopefully over time people will add theirs, this is mine.
Syed Saqib Ali Tipu, Mar 19, 2010
You are welcome !!!
Feb 24, 2010
That is exactly what I needed! Thanks Andrey.
Feb 23, 2010
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.