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

Nay Pryce's Blog:
"Dependency Injection" Considered Harmful
January 10, 2011 @ 12:05:59

While it's not PHP specific, this recent article from Nat Pryce talks about dependency injection and how the pattern could be considered harmful in the wrong (framework's) hands.

There are two aspects to Dependency Injection. Firstly, an object's interface should define the services that the object requires as well as those it provides. Secondly, the code that satisfies the requirements of an object by giving it a reference to the services of is collaborators is external to both the object and its collaborators. [...] The name "Dependency Injection" only relates to the second aspect. And worse, makes it sound like dependencies are "injected" through the object's encapsulation boundary rather than explicitly defined as part of the object's API.

He gives an example from the GOOS project where objects are independent and APIs are defined in such a way that any dependencies are clearly distinguished. "Code that composes objects is separate from the objects being composed".

The end goal is to need less and less code to write more and more functionality as the system grows.

Be sure to check out the comments on the post for some other good opinions and suggestions regarding dependency injection and its use in frameworks.

0 comments voice your opinion now!
dependency injection harmful opinion framework


blog comments powered by Disqus

Similar Posts

Henrik Bjørnskov's Blog: Symfony2: How to do a Wizard (multistep form) with Doctrine2

Juozas Kaziukenas' Blog: Why Zend Framework?

Alvaro Videla's Blog: Reply to "Scala is Easier than PHP"

Seldo.com: PHP needs to die. What will replace it?

International PHP Magzine: Poll Question: Do you believe the following about PHP?


Community Events











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


framework opinion podcast symfony2 example security package overview unittest language release introduction composer hhvm hack install facebook component code application

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