Home

Awesome

Singleton

Ensure a class has one instance, and provide a global point of access to it.

Why We Use It

Why We Regret Using It

In the short term, the Singleton pattern is relatively benign. Like many design choices, we pay the cost in the long term. Once we've cast a few unnecessary singletons into cold hard code, heres the trouble we've bought ourselves:

Its a global variable

The Service Locator pattern does make an object globally available, but it gives you more flexibility with how that object is configured.