Singleton class Vs Static class

Singleton class

Singleton is a design pattern which restricts instantiation of a class to a single object which means you can create one and only one object of a Singleton class. There could be multiple ways to create Singleton class, you may refer a very good article on different ways of creating Singleton class.

Static class

In C#, static class is a class which has all members (data members, constructor, methods etc.) as static. Static class is implicitly sealed so it can’t be inherited.

Key differences between Singleton class and static class

  • Singleton class can implement interface and it can also extend class whereas static class can’t (As static class is implicitly sealed class).
  • Singleton class can have one and only one object instantiate whereas you can’t create any instance of static class.
  • Singleton can have non-static members whereas static class has all its members static.
  • Singleton can use polymorphism whereas static class can’t.
  • Purpose of static class is to provide utility methods and shared data whereas Singleton serves different purpose.

Note: Here all the definitions and differences are for C# language.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s