~/talk

Refactoring C++ Code for Unit testing with Dependency Injection

Talkat CppCon 2024 · on Sunday, 2024-09-15· [testing, developer-experience]
links:none on file
slides:none on file

Shows concrete DI techniques and their tradeoffs: link-time substitution works but is brittle and discouraged, inheritance and interfaces give rich mocks, templates shave virtual overhead but bloat legacy builds, and type erasure (std::function / invocable) is the most versatile. Demonstrates refactoring a “god” class into layered components, using constructor injection or dependency-provider std::function for lazy resources, replacing setters/method-injection where they break APIs, and a real example where a 165‑method interface gets tamed into testable units.

AI-written summary · about

  1. 0:00Introduction
  2. 2:36Dependency injection basics
  3. 6:48Dependency injection methods
  4. 10:19Inheritance as a dependency injection mechanism
  5. 13:34Templates for dependency injection
  6. 16:26Type erasure for DI
  7. 19:59Null objects for testing
  8. 22:29Constructor vs method injection
  9. 26:46Real-world dependency injection roadblocks
  10. 33:22Refactoring legacy code
  11. 45:23Legacy code challenges
  12. 55:45Dependency injection truths in production systems
  13. 57:27Key takeaways
  14. 1:01:25Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.