a design pattern that restricts the instantiation of a class to a single object
Key Characteristics of a Singleton:
- One Instance: Only one object of the class can be created throughout the application’s lifetime.Â
- Controlled Access:Â A specific method (oftenÂ
getInstance()
) is used to retrieve the single instance, preventing direct instantiation. - Global Point of Access: The singleton instance is accessible from anywhere in the application.
Other facts
- Cannot be extended by other class
- Singleton can extend other class
- Cannot have a constructor