In my previous article I explained about Singleton Design Pattern. Today we discuss about what are the differences between Singleton and Static classes.
- Both Singleton Class and Static classes maintain single instances only, but we access the singleton class through object whereas we cannot create for static class. So singleton class data stores in Heap whereas static class data stores in Stack.
- We can clone the object of Singleton class whereas Static class is not object level.
- The basic difference is Singleton class can inherit interface whereas Static class cannot inherit interface. This is the main advantage of Singleton class as compared with the static class.
- Static class should have all static members whereas Singleton class can have static and non-static members.
- Singleton class follows OOP's concepts whereas static class cannot.
- Static class by default thread-safe whereas you have to take care about thread-safe while implementing Singleton class.
- Singleton instance can be passed as parameter to another method whereas it is not possible in the case of static class, for static class we can pass only static members.