工場のパターンがどのように適用されるのかわかりません。
このコードを例にすると:
class Car
{
protected $_engine;
protected $_frame;
protected $_wheels;
public function __construct($engine,$frame,$wheels)
{
$this->_engine = $engine;
$this->_frame = $frame;
$this->_wheels = $wheels;
}
}
class Engine
{
protected $_hp;
public function __construct($hp)
{
$this->_hp = $hp;
}
}
class Frame
{
protected $_type;
protected $_length;
public function __construct($type,$length)
{
$this->_type = $type;
$this->_length = $length;
}
}
class Wheels
{
protected $_diameter;
public function __construct($diameter)
{
$this->_diameter = $diameter;
}
}
class CarFactory
{
// ???
}
工場は自動車のすべての部品をどのように作成することになっているのですか? すべての部品に工場が必要ですか? もしそうなら、CarFactory はそれらについてどのように知っていますか? IOC、DI、およびファクトリ パターンの組み合わせは、すべてまたは何かを開始する場所を混乱させます。私はそれらすべての利点を理解しています(と思います)。
ここで依存性注入はどのように機能しますか? すべてのパーツを独自のオブジェクトにすることもできましたが、簡単にするために、ここでは省略しました。
うまくいけば、私の質問は十分に明確です。
前もって感謝します!