Singleton
creationalGuarantees a single instance of a class
Type: patternPrinciples
Single instanceGlobal access pointLazy initialization possible
When to use
When you really need a single instance (logging, config)
When not to use
Almost always - prefer DI
Pros and Cons
Ventajas
- + Single instance control
- + Lazy initialization
- + Global access point
Desventajas
- - Difficult to test
- - Global state (anti-pattern)
- - Hides dependencies