What is singleton class? Where is it used?- The purpose of singleton is to control the object creation, limiting the number of the objects to one only.
- Since it has only one instance any instance fields of a singleton will occur only once per class like the static fields.
- They have access control to resources as the database connections or the sockets.
- A class is defined as 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 some of the uses of singleton class.
1. The access of the object is controlled.
2. When "just-in-time" instantiation is needed and needed globally.