Dependency Injection in C++ - A Practical Guide
summary
Practical strategies for adding DI to a legacy C++ ticker-plant: rejects link-time substitution (avoid), compares inheritance/virtual interfaces, templates and std::function/type erasure, and shows Google Mock usage and null-object stubs. Addresses injection styles (setter/method/constructor), lazy construction via a dependency-provider callable, and signature-preserving forwards/defaults for APIs. Demonstrates refactoring god classes into gather/apply/distribute tiers, fixes a 167-method interface pain point, cuts heavy inheritance code by about 60%, and applies changes in production without feature flags.
AI-written summary · about
chapters (13)
- 0:00Introduction and motivation
- 3:01Myths and current testing
- 6:06Essence of DI and system analysis
- 8:36Basic injection methods
- 14:13Advanced injection techniques
- 20:16Stubs and null objects
- 23:08Setter and method injection
- 25:55Constructor injection
- 28:09Conceptual and applied DI
- 31:06Refactoring strategies
- 38:15Managing complex dependencies
- 43:43Legacy code techniques
- 50:25Conclusion and final insights
related talks
01h 29mDependency Injection in C++ - A Practical Guide
01h 02mRefactoring C++ Code for Unit testing with Dependency Injection
01h 03mHow to Use C++ Dependency Injection to Write Maintainable Software
32mCompile- and Run-Time Dependency Injection
05mConcept Driven Design with Dependency Injection
58mA Practical Guide to Loose Coupling
07mTDD/BDD and DI
46mTestability and C++ API Design
