Singleton Vs Static Class

"Singleton designing pattern deals with a pattern in which instantiation of object is under control and restrict count by one by making constructor as private "
"A Static mean a class that has only static members"

A Singleton class is supposed to have one and only one instance while a static class is never instantiated.

The singleton pattern has several advantage over the static class pattern
  1. A Singleton can extend class and implement interfaces, while a static class can not.
  2. A singleton can be initiated lazily or asynchronously while a static class is generally initialized when it is first loaded
  3. A singleton class can be extended and its methods overridden , We can not override static methods with non static method

Comments

Post a Comment

Popular posts from this blog

Composite Design Pattern by example

State Design Pattern by Example

Eclipse command framework core expression: Property tester