The singleton pattern ensures a class has only one instance and provide a global point of access to it.
Example of Singleton pattern in real-world application:
- Logging. Logger object instance needs only exist once across the application life cycle. Especially true when the log is written to a locking-mechanism store, such as a Windows file.
- Load Balancer. A load balancer type of situation must only exist as a singleton object to direct which resource is available to a invoker.
- IoC Container. Underneath any IoC container, there’s singleton instance object that controls what class implementation to pass given the contract.
Further read: GOF’s Pattern: Singleton