Difference Between Static Class and Singleton Class In C# With Example

preview_player
Показать описание
Static class is a class which we cannot create an instance or object of this class. Static class must have static variables, properties, and methods. Static class cannot follow the OOP rules. It does not implement inheritance.

Static class is not a design pattern hence it also not follow the OOP rules. Static class methods, variables, and properties has been shared among all the applications and access by the using class name then dot and follow by the method name. Static class cannot pass as a parameters in method.

Singleton class is a class which only and only one instance. Singleton class will follow the OOP rules and its a pure OOP implementation. Singleton class pass as a parameters in method. Singleton class is a design pattern which use the OOP rules and this is the feature the makes singleton class is a design pattern.
Рекомендации по теме
Комментарии
Автор

This does not explain when to use singleton class over static class. Why we need to even pass singleton as a parameter? Give me a reason I must use Singleton pattern not a static class.

BimalDaslol