In this second video of the SOLID series, we will see what the Dependency Inversion Principle is and what benefits it brings. As always, we will approach it in the most practical way possible, refactoring code to apply this principle. In the previous videos, we already saw how to configure namespaces following PSR-4 and use Composer's autoloader, how to apply the PSR-2 coding style standard, and, more specifically in the SOLID series, we have already seen the Single Responsibility Principle and Interface Segregation Principle. I recommend you take a look at them :)
Video Index
- 1:03 - Explanation of base code (context)
- 2:50 - Scenario 1: Highly Coupled Code and creating instances of collaborators at the point they are needed
- 3:55 - Why is code coupling bad?
- 6:10 - Class diagram of scenario 1
- 7:10 - Scenario 2: Refactoring to introduce the concept of dependency injection. Highly coupled code but creating instances of collaborators outside the client class
- 9:00 - What benefits does dependency injection have?
- 10:39 - Scenario 3: Refactoring to apply the Dependency Inversion Principle (Dependency Inversion Principle, DIP). Decoupled and changeable code.
- 11:38 - Explanation of the introduced interface. Design by contract
- 13:35 - What benefits does dependency inversion have?
- 15:30 - Class diagram applying the dependency inversion principle
- 16:05 - Dependency inversion explained like you've never seen before :D
Video
Related Material
- [article] Inversion of Control Containers and the Dependency Injection pattern: Article by Martin Fowler about injection and dependency inversion
- [paper] The Dependency Inversion Principle: Paper published by ObjectMentor
- [tutorial] SOLID: Part 4 - The Dependency Inversion Principle: Series of tutorials from Tuts+ on SOLID
- [post] The “D” Doesn’t Stand For Dependency Injection
Upcoming Videos
- Interview!
- DTOs / Anemic Domain Models vs Domain Models (Intermediate)
- Composition over Inheritance - A Turning Point (Intermediate)