Explain singleton pattern?
If a system only needs one instance of a class, and that instance needs to be accessible in many different parts of a system, you control both instantiation and access by making that class a singleton.
Ensure a class has only one instance, and provide a global point of access to it.
Singletons are very similar to GlobalVariables, and are often implemented with global variables, even if they masquerade as class members.
The Singleton ensures that there can be only one instance of a Class and provides a global access point to that instance. Singleton is a "Gang of Four" Creational Pattern.
The Singleton pattern is often implemented in Database Classes, Loggers, Front Controllers or Request and Response objects.
Leave a Reply.