Singleton over static class
When would you prefer singleton over static class? Please give a real world example with proper reasoning.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anil KumarPosted Apr 6, 2015, 8:55 AM
Below I have provided some scenarios below where you can apply the both
Use static classes where you have bunch of similar functions like math class for add, subtract, multiply, divide etc.. We normally use static classes for helper classes or similar utilities classes where we can't afford to initial the class each time we want to use the function.
Singelton - Use singelton where you want instance of a object to be globally available to all users. You can you singelton in Thread pools, SQL Connection Pools, Registry objects, Objects handling user preferences, Caches, Factory classes, Builder classes and Statistics utilities like a hit counter etc..
Ramesh MaruthiPosted Apr 6, 2015, 8:42 AM
http://www.c-sharpcorner.com/UploadFile/akkiraju/singleton-vs-static-classes/
http://dotnet.dzone.com/news/c-singleton-pattern-vs-static-
Riddhi ValechaPosted Apr 6, 2015, 8:20 AM
http://www.c-sharpcorner.com/UploadFile/e70b61/real-example-of-singleton-design-pattern/
Vineet KumarPosted Apr 6, 2015, 6:53 AM
I appreciate your response, but as said in question, I need a real world example where you can apply these concepts. The heavy weight words (such as polymorphism, OO blah blah) are not something I am looking for :)
Anil KumarPosted Apr 6, 2015, 6:41 AM