[PEPr] Comment on Networking::SNMP

From: Date: Fri, 18 Mar 2011 02:02:09 +0000
Subject: [PEPr] Comment on Networking::SNMP
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-54162@lists.php.net to get a copy of this message
All looks great to me. I would personally amend point 13 a little bit. Dependency injection is great for unit testing, but can be a bit of an inconvenience when using the code in the real world. Instead, make it optional. //Bad function bar() { $bar = new Bar(); return $bar->doSomething(); } //Good function bar(Bar $bar = null) { if (!$bar instanceof Bar) { $bar = new Bar(); } return $bar->doSomething(); } //Good class X { function __construct($bar = null) { if (!$bar instanceof Bar) { $bar = new Bar(); } $this->bar = $bar; } function bar() { return $this->bar->doSomething(); } } -- http://pear.php.net/pepr/pepr-proposal-show.php?id=581

« previous php.pear.dev (#54162) next »