13. May 2013 05:02
A static class is a class with static member variables and methods.
A singleton is a design pattern which makes available only a single created instance of that class.Since it allows a single instance of the class,it is possible to pass this instance object as parameter to methods.
Both singleton and static class shares the variable
Following are the major difference between a Static class and a singleton class which I can point out.
1) No need of static keyword usage with every class member.
1) singletons can implement interfaces and can derive from a base class
2) Singleton can derive a base class
3) Singleton class can be passed as a parameter
4) All object orientation principles applies to singleton class
5) Implementation is not so simple as static class.
No Instance created and methods and members are accessed at class level directly.
Can not Implement interfaces or derive from base class
Implementation is simple
No object creation and hence can not pass as a method parameter.
Static classes are easy to imlement than singleton.So the choice should purely be based on the requirement.
It doesn't make any meaning to go for a singleton class where in it is more than enough to have a static class instead.