In the first overview; we see both singleton class and static class are look similar. But there are many difference and here are the major points.
The big difference between a singleton and a bunch of static methods is that singletons can implement interfaces (or derive from useful base classes, although that's less common IME), so you can pass around the singleton as if it were "just another" implementation.
A singleton allows access to a single created instance - that instance (or rather, a reference to that instance) can be passed as a parameter to other methods, and treated as a normal object.
A static class allows only static methods.
Singleton object stores in Heap but, static object stores in stack.
We can clone the object of Singleton but, we can not clone the static class object.
Singleton class follow the OOP(object oriented principles) but not static class
we can implement interface with Singleton class but not with Static class.
No comments:
Post a Comment