What is singleton class? Where is it used?- It is a design pattern which restricts the instantiation of a class to one object.
- The main purpose of singleton class is to control object creation, limiting the number of objects to one only.
- A class is defined as a singleton class, if and only if it can create only one object.
- This class is useful when only one object is to be used in the application.
The following are the uses of the singleton class:
1. The access of the object is controlled. 2. When "just-in-time" instantiation is needed globally. 3. It is useful when one object is needed to coordinate actions across the system.
|