In today’s object oriented world, we have application like the size of a sea and we create and destroy objects in seconds inside the application.
There is instances where we need to have a situation of creating and maintaining a single instance of a class. The solution to that is called “Singleton”.
There are various way of implementing singleton pattern but the key point is that all will have a private constructor so that no public creation of that class is possible.
Lets look at them.
Eager Initialization
This method involves the instantiation of a class much before it is even used. Simple way is
Lazy Initialization
This is just opposite of the 1st way. The class is instantiated when the client requests the creation of the class.
Simple drawback to the above implementation is parallel invocation. to avoid creation of two parallel objects, lets synchronize a bit more.
Hope you liked the explanation till this point. Watch this space for further ways of using Singleton interface.