Dependency Injection and method signatures
Posted
by
sunwukung
on Programmers
See other posts from Programmers
or by sunwukung
Published on 2011-04-27T18:19:39Z
Indexed on
2013/10/21
22:03 UTC
Read the original article
Hit count: 233
I've been using YADIF (yet another dependency injection framework) in a PHP/Zend app I'm working on to handle dependencies. This has achieved some notable benefits in terms of testing and decoupling classes.
However,one thing that strikes me is that despite the sleight of hand performed when using this technique, the method names impart a degree of coupling.
Probably not the best example -but these methods are distinct from ... say the PEAR Mailer. The method names themselves are a (subtle) form of coupling
//example
public function __construct($dic){
$this->dic = $dic;
}
public function example(){
//this line in itself indicates the YADIF origin of the DIC
$Mail= $dic->getComponent('mail');
$Mail->setBodyText($body);
$Mail->setFrom($from);
$Mail->setSubject($subject);
}
I could write a series of proxies/wrappers to hide these methods and thus promote decoupling from , but this seems a bit excessive. You have to balance purity with pragmatism...
How far would you go to hide the dependencies in your classes?
© Programmers or respective owner