java - Magento 类覆盖设计模式的正式名称?

标签 java php oop spring magento

Magento 是一个新的(过去 5 年)基于 PHP 的电子商务系统,其架构类似于 Java Spring 框架(或者有人告诉我)

框架的一个特点是某些类不是直接实例化的。而不是做类似的事情

$model = new Mage_Foo_Model_Name();

将标识符传递给全局应用程序对象上的静态方法

$model = Mage::getModel('foo/name');

这会为您实例化该类。

这种方法的好处之一是 getModel 检查全局配置系统中的 foo/name 标识符,并实例化它在配置系统中找到的类名。这允许您通过单个配置更改来更改模型系统范围内的行为。

是否有描述此系统/设计模式的正式名称、四人帮或其他名称?实例化本身看起来像一个经典的工厂模式,但我对整个“通过配置覆盖系统中的类”方面特别感兴趣。是否有涵盖此内容的名称/概念,或者它是否包含在工厂的世界观中?

最佳答案

这看起来像工厂设计模式。


引用 Factory method pattern 的维基百科条目(强调我的):

it deals with the problem of creating objects (products) without specifying the exact class of object that will be created.
The factory method design pattern handles this problem by defining a separate method for creating the objects, which subclasses can then override to specify the derived type of product that will be created.

和:

Outside the scope of design patterns, the term factory method can also refer to a method of a factory whose main purpose is creation of objects.


其他几个有趣的链接:

关于java - Magento 类覆盖设计模式的正式名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2723899/

相关文章:

java - java中Process中的字符串数组在参数中有空格

java - findViewByID() 不起作用。我应该怎么办?

java - 如何在Java Swing中使用Label实现 View ?

php - 更改 codeigniter 中的 url

php - CLI Doctrine 2 - 索引已经定义

swift - 在 Swift 类中获取和设置数组

java - 无法在 ActiveMQ 中使用来自嵌入式远程代理的消息

php - PHP 数量更新仅影响一行

Java:如何比较 List<String> 与 List<List<String>>?

c# - 使用从 DynamicObject 继承的子类时监视非动态方法调用