Magento 2は、注射不可のファクトリクラスを使用しています。
たとえば製品クラス:ProductFactory
たとえば顧客クラス:CustomerFactory
私はここで工場パターンのタイプが何であるか理解できませんか?
1つのファクトリクラスに関連付けられている各クラスのため。私はその何かが重複していると考えています。
なぜ私たちはのための抽象工場作成するべきではないCustomerFactory、ProductFactoryなど?
また、たとえば:
私たちは、渡すことができますAbstractFactoryタイプのチェックのための代わりProductFactoryにProductRepositoryクラスのコンストラクタ。
したがって、ProductRepositoryとの間の密結合を避けることができますProductFactory
抽象ファクトリークラス:
namespace Magento\Framework\ObjectManager\Code\Generator;
/**
 * Abstract Factory class 
 */
abstract class AbstractFactory 
{
    /**
     * Object Manager instance
     *
     * @var \Magento\Framework\ObjectManagerInterface
     */
    protected $_objectManager = null;
    /**
     * Instance name to create
     *
     * @var string
     */
    protected $_instanceName = null;
    /**
     * Create class instance with specified parameters
     *
     * @param array $data
     * @return \Magento\Catalog\Model\Product
     */
    public function create(array $data = array())
    {
        return $this->_objectManager->create($this->_instanceName, $data);
    }
}抽象ファクトリー実装:
namespace Magento\Catalog\Model;
use Magento\Framework\ObjectManager\Code\Generator\AbstractFactory;
/**
 * Factory class for @see \Magento\Catalog\Model\Product
 */
class ProductFactory extends AbstractFactory
{
    public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $instanceName = '\\Magento\\Catalog\\Model\\Product')
    {
        $this->_objectManager = $objectManager;
        $this->_instanceName = $instanceName;
    }
}オブジェクトマネージャーとファクトリーの関係は何ですか?
連鎖オブジェクトは非常に多くあります。
- たとえば、 - ProductRepositoryここではクライアントとして呼び出すことができますが、- Productオブジェクトが必要です。
- このため、特定の - ProductFactoryオブジェクトに依存します。
- ProductFactoryオブジェクトはオブジェクトに依存し- ObjectManagerます。
- ObjectManagerオブジェクトはファクトリオブジェクトに依存します(こちら- Developer Object)。
もちろん、彼らは疎結合にインターフェースを使用しています。まだ本当に混乱しているフロー。
Magento 2の工場出荷時のパターンと、Magento 1との違いを詳しく教えてください。