TechyMedia

A .NET Technology blog | .NET,C# Progamming,C# tutorials,WPF WCF|Software Engineer

NAVIGATION - SEARCH

Difference Between Static Class And Singleton Class

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.

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.

Singleton Class

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.

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.

Pingbacks and trackbacks (1)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading