Last week I gave a presentation to my team on dependency inversion and dependency injection in PHP. Dependency inversion is the “D” in the the SOLID object oriented design principles, and dependency injection is a design pattern for implementing it.
We previously learned the single responsibility principle (PDF) (the “S” in SOLID). To me, dependency inversion is the next logical topic. Single responsibility is about how to write objects that do one thing; dependency inversion is about how you wire those objects together into robust, working software.
This was a fun presentation, and I think the slides work well even without my narration. Several of the code examples are from the new version of Shashin, where I’m applying the principles. I’m still learning how to best apply them, so feedback in the comments section is welcome.