Retiring the Singleton Pattern, Concrete Suggestions for What to Use Instead
summary
Replaces global singletons with an explicitly passed com wrapper that defaults to a lazy-initialized static to keep source and ABI compatibility, enabling dependency injection so previously-opaque functions become unit-testable; uses std::function / std::ref to avoid copies of non-copyable internals and a one-time init pattern (function-local statics or compiler do_once) to fix a doubled file-descriptor bug. Tests use GoogleTest, perf checks use QuickBench, and benchmarks show only minor overhead in practice.
AI-written summary · about
chapters (15)
- 0:00Start
- 4:50What's currently out there
- 9:48Drawbacks of a Singleton
- 11:19Reasons given for using a Singleton anyway
- 13:21Singleton or Not?
- 34:33Preserving The Application Binary Interface (ABI)
- 37:52Lazy Initialization - pre C++11
- 39:27Lazy Initialization - Modern C++
- 40:28Separation of Concerns
- 42:04Phased Introduction
- 45:47Initialization Dependencies
- 50:59Grouping Dependencies
- 51:39Multiple Dependencies
- 51:54Brute force
- 58:10Stateful Dependencies
related talks
01h 02mRetiring the Singleton Pattern: Concrete Suggestions for What to use Instead
05mOn using singletons in C++
01h 23mInvestigating Legacy Design Trends in C++ & Their Modern Replacements
58mA Practical Guide to Loose Coupling
01h 29mDependency Injection in C++ - A Practical Guide
49mWorking with C++ Legacy Code
01h 28mLaw of Demeter: A Practical Guide to Loose Coupling
01mTalk Preview - The Surprising Power of Small Wrapper Classes in C++
