- Guarantee that only one object is instantiated for a given class.
- In Java, we can use private constructor + static method (
getInstance()
) to ensure there’s only one instance in single-threaded applications.
- Be careful when using this pattern in multi-threaded applications. Because multiple copies of the same program are running in parallel, the above implementation fails.