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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Anil KumarRank #2,740 · 511 reputationPosted Apr 6, 2015, 2:41 AM EDT
Vineet KumarRank #1,751 · 861 reputationPosted Apr 6, 2015, 2:53 AM EDT
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 :)
Riddhi ValechaRank #794 · 2.9K reputationPosted Apr 6, 2015, 4:20 AM EDT
http://www.c-sharpcorner.com/UploadFile/e70b61/real-example-of-singleton-design-pattern/
Ramesh MaruthiRank #937 · 2.2K reputationPosted Apr 6, 2015, 4:42 AM EDT
http://www.c-sharpcorner.com/UploadFile/akkiraju/singleton-vs-static-classes/
http://dotnet.dzone.com/news/c-singleton-pattern-vs-static-
Anil KumarRank #2,740 · 511 reputationPosted Apr 6, 2015, 4:55 AM EDT
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..