0
我有去像緊耦合與DI門檻
class A
{
public $b, $c;
//Inject D and E here? (B $b, C $c, D $d, E $e, ...)
public function __construct(B $b, C $c)
{
$this->b = $b;
$this->c = $c;
}
public function main()
{
if (rand(0,1)) {
new D();
} else {
new E();
}
}
}
我應該在A
構造函數注入可能D
和E
類代碼?這裏的問題是項目的層次結構遵循這個樹狀結構,從而使上層節點A
保持其子節點的所有依賴關係。或者在某個時候足夠健全地成爲stupid?