Singleton pattern is a design solution where an application wants
to have one and only one instance of any class.It saves memory because object
is not created with each request. Only single instance is reused again and
again.
But how
to make any class singleton is not so easy task, because there are several way
in which singleton can break.
Steps:
1.
Make
constructor private, so not directly instantiated class
2.
Make
a static method which produce existing instance if one available else new
3.
Override
clone() method. One cannot create a cloned object which also violates singleton
pattern.
4.
If
Singleton is class is serializable then once it serialized again deserialized
it, but it will not return singleton object.