Sunday, 19 July 2015

Difference between Static and Singleton classes

1)    A singleton classes allowed create only a single instance of particular class. That instance can be treated as normal object. You can pass that object to a method as parameter or you can call the class method with that Singleton object.
While static class can have only static methods and you cannot pass static class as parameter.
2)    We can implement the interfaces with the Singleton class while we cannot implement the interfaces with static classes.
3)    We can clone the object of Singleton classes; we cannot clone the object of static classes.
4)    Singleton objects stored on heap while static class stored in stack.
5)    A Singleton class can extend the classes (support inheritance) while static class cannot inherit classes.
6)    Singleton class can initialize lazy way while static class initialize when it loaded first.
7)    Static classes are sealed class while Singleton classes are not sealed.

No comments:

Post a Comment