Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Why we have to use Singlton pattern in mvc framework ? while if we can do the same by Static class & static method.

So what is the difference between SINGLTON & STATIC CLASS ?

In which scenario we can use the singlton pattern & whats benefits.
Posted
Updated 2-May-15 3:38am
v3

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search using part of your question gave over 100,000 results: Google: "difference between SINGLTON & STATIC CLASS[^] - most of which are explanations.

In future, please try to do at least basic research yourself, and not waste your time or ours.
 
Share this answer
 
Comments
Pramod Singh (C) 2-May-15 9:56am    
thnx....
Let's see. Probably you think that singleton pattern is something good. I would not agree with that — it is at best only tolerable, and should not be overused. The singleton objects gives you draconian hassles, notably in multithreading. Yes, I use this pattern myself, but only in special, exclusive situations.

Now, one can implement singletons in different ways, good and bad. Static class is the class which would prohibit the good ways, will allow only bad ones. Why? Non-static class allows to have any member in class, static and non-static (instance) once. A static class limits you to static members only. You would not be able to use any instance members. But why would you need to use an instance member? Well, to make the singleton implementation a bit less disgusting that it could be. How? Here is the example of good implementation: http://csharpindepth.com/Articles/General/Singleton.aspx[^]. (Referenced from http://en.wikipedia.org/wiki/Singleton_pattern[^].)

Please read the both articles. After reading then, you should come to understanding why your idea of using of the static class as a singleton was so bad, compared to better implementation.

—SA
 
Share this answer
 

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