News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
The Dependency Inversion Principle
May 10, 2012 @ 08:52:19

Continuing on in their series looking at the SOLID development principles, Alejandro Gervasio picks back up and looks at the "D" in the set - the dependency inversion principle.

While some central concepts in the realm of object-oriented design are generally harder to digest at first, such as separation of concerns and implementation switching, more intuitive and untangled paradigms on the other hand are simpler, like programming to interfaces. Unfortunately, the DIP's formal definition is surrounded by a double-edged curse/blessing that often makes programmers gloss over it, as in many cases there's an implicit assumption that the principle is nothing but a fancy expression for the aforementioned "programming to interfaces" commandment.

He talks about how decoupling your code and working against interfaces is only part of the equation. The other half is the actual "inversion" part of the process - the ownership that the high-level modules must have over the abstractions. He illustrates with an example, a storage module that is highly dependent on a Serializer. Using the DIP principle, he turns this around and refactors his storage class to take in an Encoder object as a part of its construction. Complete source for both versions is included.

0 comments voice your opinion now!
dependency inversion principle solid dip tutorial


blog comments powered by Disqus

Similar Posts

SitePoint PHP Blog: UTF-8 Email in PHP with eZ Components

Bnnx.com: Installing the Zend Optimizer

Procurios Blog: Fragment Cache - an introduction / PHP

Ian Christian's Blog: Creating a custom form field type in Symfony 2

CMStr.com: How to manually install Joomla 1.5+


Community Events











Don't see your event here?
Let us know!


hack unittest application performance install opinion package component series release hhvm language security framework database podcast introduction facebook symfony2 composer

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework