The big difference between a singleton and a bunch of static methods is that singletons can implement interfaces (or derive from useful base classes), so you can pass around the singleton as if it were "just another" implementation.
Static class:
Static class can not be a top level class and can not implement the interface.
It provides better performance than Singleton pattern, because static methods are bonded on compile time.
It provides better performance than Singleton pattern, because static methods are bonded on compile time.
Static class always provides the eagerly loaded however Singleton classes can be lazy loaded if it’s a heavy object.
Singleton objects:
It stored on heap while static class stored in stack.
It can have constructor while static class cannot.
It can dispose but not static class.
It can clone but not with static class (logically wrong to clone the Singleton objects).
No comments:
Post a Comment