On using singletons in C++
summary
Almost every C++ project uses singletons in one form or another, but the common static-instance pattern exposes internal structures and leaks implementation. Alternatives shown: Pimpl to hide data, an abstract base class with multiple implementations, and a static-method façade. Putting implementation into a namespace with an anonymous namespace keeps internals private but risks the static initialization order fiasco. For testing, either add a test-only reset or place implementation in a detail include so tests can access state.
AI-written summary · about
chapters (5)
related talks
01h 16mRetiring the Singleton Pattern, Concrete Suggestions for What to Use Instead
01h 02mRetiring the Singleton Pattern: Concrete Suggestions for What to use Instead
01h 20mHiding your Implementation Details is Not So Simple
01h 03mHiding Your Implementation Details in C++ is Not So Simple
01h 40mDesign Patterns: Examples in C++
01h 28mLaw of Demeter: A Practical Guide to Loose Coupling
01h 29mDependency Injection in C++ - A Practical Guide
01mTalk Preview - The Surprising Power of Small Wrapper Classes in C++
