If you are looking the answer for the Difference between static class and singleton pattern, read this post.This also explains the advantages of singleton pattern over static class and when to use singleton and static class in c#
A static class is a class with static member variables and methods.
A singleton is a design pattern which makes available only a single object of that class.Since it allows a single instance of the class, it is possible to pass this object(instance) as a parameter to methods.
Both Singleton and static class shares variables.
Table of Contents
See below the major difference between a Static class and a singleton class
Singleton pattern is creational design pattern type. Singleton ensures that you create only one instance of a class that will exist throughout your application life time.
In Singleton class,
1) No Instance created and methods and members are accessed at the class level directly.
2) Can not Implement interfaces or derive from base class
3) Implementation is simple
4) No object creation and hence can not be passed as a method parameter.
Static classes are very easy to implement than a singleton.The choice of selection should purely be based on the requirement.It doesn’t make any meaning to go for a singleton class when it is enough to have a static class instead.
Here we covered the difference between static class and singleton pattern, the advantages of singleton pattern over static class and when to use singleton and static class in c#.Hope you find this article helpful.Give your valuable feedback in the comment section below.
You may like to read Static Class in C#
OWIN (Open Web Interface for .NET) is an interface between web servers and web applications…
JSON (JavaScript Object Notation) is a commonly used data exchange format that facilitates data exchange…
The CAP theorem is also known as Brewer's theorem. What is CAP Theorem? CAP theorem…
Some of the Key factors that need to consider while architecting or designing a software…
The Interface Segregation Principle (ISP) is one of the SOLID principles of object-oriented design. The…
The Single Responsibility Principle (SRP), also known as the Singularity Principle, is a software design…