This design pattern is considered a creational pattern, as this pattern provides one of the best ways to create an object.

There are many times when we only need one instance of an object and if we instantiate more than one we’ll run into all sorts of problems, like incorrect program behavior, overuse of resources, or inconsistent results.

The singleton pattern involves only one class which is required to instantiate itself and to make sure it creates no more than one instance.

The only way to get the object of this class is by using the sc static variable, which ensures only one object is there.

So, this is our singleton class, which makes sure that only one object of the class gets created and, even if there are several requests, only the same instantiated object will be returned.

Related Articles