Retiring the Singleton Pattern
summary
Argues for removing singletons by replacing them with lightweight wrapper classes, preserving API/source compatibility and allowing a phased rollout across hundreds of call sites (avoids touching 150+ files at once). Uses lazy construction, type erasure via std::function and reference semantics with std::ref, templates for service buckets, and mocks with Google Test so previously opaque functions become testable. Provides concrete refactor steps, handles interdependent initialization, and reports real uptake in production code.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 4:18What is wrong with Singleton patterns
- 8:12Why use Singletons
- 12:03Refactor Singleton usage
- 18:52Testable functions without Singleton
- 27:19Phased Singleton replacement
- 30:37Initialization dependencies
- 37:21Grouping dependencies
- 47:49Refactoring benefits
- 51:42Question and answer session
related talks
01h 00mHow to Use Dependency Injection to Write Maintainable Software
01h 07mDependency Injection Patterns: Efficiency and Usability
03mLightning Talk: Dependency Injection for Modern C++
01h 01mBack to Basics: Designing Classes (part 1 of 2)
15mYou Might Not Need Classes
56mLaw of Demeter: A Practical Guide to Loose Coupling
44mDisposable-First Architecture: Build Fast, Kill Faster
24mA Few Good Design Patterns
