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
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