In continuation of my posts on Creational design patterns, I will be
discussing about the Singleton pattern in this post. You can read about
the other patterns from the following links.
Singleton pattern deals with ensuring that there is only one instance of
a class and providing a single global access point to that object. It
also ensures that the object is not created until its actually needed.
As you can see from the above example the 2 instances of the
SingletonPerson object are the same and so are their properties viz.
Name, Age and Address. We can use the singleton pattern when we need to
create only one instance of a class or when we need to provide
controlled access to an instance.
In my next post I will be writing about the Abstract Factory Pattern.
Comments