Law of Demeter: A Practical Guide to Loose Coupling
summary
Shows concrete C++ examples that break and fix the Law of Demeter and claims applying LoD plus Single Responsibility and Dependency Inversion yields code that’s easier to change and test. Demonstrates constructor-based dependency injection, use of strong types and Concepts to catch mistakes at compile time, compares type erasure, std::variant and std::any tradeoffs, and wires objects in a composition/factory layer. Provides fakes and BDD-style tests as proof that the refactor makes the code looser coupled and more testable.
AI-written summary · about
chapters (30)
- 0:00Introduction to loose coupling
- 0:33Motivation for better design
- 1:36The essence of good design
- 2:52Why tight coupling fails
- 5:43Anti-patterns to avoid
- 7:01Analyzing bad code examples
- 9:28Common software problems
- 10:38The Law of Demeter
- 11:55How to fix tight coupling
- 13:32Applying TDD and SOLID
- 14:38Solid vs. Stupid principles
- 15:52Single Responsibility Principle
- 19:36Dependency Injection
- 22:54Constructor injection tips
- 24:53Pitfalls of Dependency Injection
- 27:17Managing object creation
- 30:15Refactoring chains of calls
- 31:43Strongly typed APIs
- 33:33Benefits of strong types
- 35:33Dependency Inversion Principle
- 37:18Polymorphism in C++
- 39:31Type Erasure and std::variant
- 41:41Injecting polymorphism
- 43:27Templates and Concepts
- 45:16Functional programming approach
- 47:57Choosing the right abstraction
- 48:58Refactoring example walk-through
- 50:33Separating creation and logic
- 52:03BDD and testing examples
- 53:46Summary and takeaways
related talks
01h 00mHow to Use Dependency Injection to Write Maintainable Software
01h 03mBreaking Dependencies: The SOLID Principles
03mLightning Talk: Dependency Injection for Modern C++
01h 07mDependency Injection Patterns: Efficiency and Usability
58mGetting a grip on your code dependencies
44mDependencies; Devil or Darling?
41mUsing Boundary-Driven Development to beat code complexity
01h 38mBreaking Dependencies: The Path to High-Quality Software
