Magento设计模式 [英] Magento Design Patterns

查看:145
本文介绍了Magento设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Magento,IMHO代表了一个基于深思熟虑的编码原则的PHP系统 - 可重用的设计模式是其中之一。关于PHP系统的一个例子,我认为它可以被认为是非常前沿的,因此从架构的角度来看,值得考虑。



据了解, OOP开发人员可以使用许多设计模式。在Magento这样的开源系统中使用这种模式,开发人员可以在实际使用和原位查看这些模式的示例,而不是在有时可能会变得非常棘手的示例中,甚至有点误导。 / p>

因此,我想知道Magento程序员在开发Magento时使用的是什么模式,而不是我下面列出的模式。



作为一个说明,我明白,这些模式中的一些是由于在Zend框架上构建的,MVC / Front Controller是其中的几个,



显而易见的是:



工厂:

  $ product = Mage :: getModel('catalog / product'); 

Singleton:

  $ category = Mage :: getSingleton('catalog / session'); 

注册表:

  $ currentCategory = Mage :: registry('current_category'); 


解决方案

原型: p>

 法师:getModel('catalog / product') - > getTypeInstance(); 

事件观察对:

 #PHP 
Mage :: dispatchEvent('event_name',array('key'=> $ value));

#config.xml
< config>
< global>
< events>
< event_name>
< observers>
< unique_name>
< class> Class_Name< / class>
< method> methodName< / method>
< / unique_name>
< /观察者>
< / event_name>
< / events>
< / global>
< / config>

对象池

  $ id = Mage :: objects() - > save($ object); 
$ object = Mage :: objects($ id);

迭代器

 法师:: getModel( '目录/产品') - > getCollection(); 


Magento, IMHO, represents a PHP system that is built on well thought-out coding principles - reuseable design patterns being one of them. In terms of an example of a PHP system, I think it can be considered pretty cutting edge and therefore worth considering from an architectural point of view.

As I understand it, there are many design patterns that are available to the OOP developer. Seeing such patterns being put to use in an open-source system such as Magento allows a developer to view examples of such patterns in real use and in situ, rather than in examples that can sometimes be rather achedemic, and even a little misleading.

As such, I am wondering what patterns, other than the ones I have listed below, Magento programmers have used when developing for Magento.

As a note, I understand that some of these patterns are in place as a consequence of being built on the Zend Framework, MVC / Front Controller being a couple of them,

The obvious ones are:

Factory:

$product = Mage::getModel('catalog/product');

Singleton:

$category = Mage::getSingleton('catalog/session');

Registry:

$currentCategory = Mage::registry('current_category');

解决方案

Prototype:

Mage:getModel('catalog/product')->getTypeInstance();

Event-Observer Pair:

# PHP
Mage::dispatchEvent('event_name', array('key'=>$value));

# config.xml
<config>
    <global>
        <events>
            <event_name>
                <observers>
                    <unique_name>
                        <class>Class_Name</class>
                        <method>methodName</method>
                    </unique_name>
                </observers>
            </event_name>
        </events>
    </global>
</config>

Object Pool:

$id = Mage::objects()->save($object);
$object = Mage::objects($id);

Iterator:

Mage::getModel('catalog/product')->getCollection();

这篇关于Magento设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆