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