the.com/singleton
The design pattern for commitment-phobes: exactly one instance, forever, no exceptions.
means A class designed so only one instance of it can ever exist in a running program, with a single global point of access to that instance.
from Borrowed from card games and math, where a 'singleton' means a set or group containing exactly one member — think a lone card of its suit in a bridge hand, or a mathematical set with a single element. Software engineers adopted the term directly: the Gang of Four's 1994 'Design Patterns' book gave it its famous programming meaning, naming the pattern after that same idea of 'a group of exactly one.'
- origin
- Named after sets with exactly one element
- real use
- Database connections, loggers, config managers
- hidden cost
- Secretly global state wearing a disguise
- testing nightmare
- Hard to mock, hard to reset between tests