It implement the concept of factories and deals with the problem of creating objects without specifying the exact class of object that will be created.
$product = Mage::getModel('catalog/product');
It restricts the instantiation of a class to one object. It will refer to same object each time called.
$category = Mage::getSingleton('catalog/session');
It is a way to store information throughout your application.
Mage::register('key',$value); //stores $currentCategory = Mage::registry('key'); //retrives
It determines the type of object to create. In Magento it can be Simple, Configurable, Grouped, Bundle, Downloadable or Virtual types.
It is mainly used to implement distributed event handling systems. Here the subject maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<config> <global> <events> <event_name> <observers> <unique_name> <class>Class_Name</class> <method>methodName</method> </unique_name> </observers> </event_name> </events> </global> </config>
It is used to reuse and share objects that are expensive to create.
$id = Mage::objects()->save($object); $object = Mage::objects($id);
It is used to traverse a collection and access the collection’s items.
It is used to defer initialization of an object until the point at which it is needed.
$collection_of_products = Mage::getModel('catalog/product') ->getCollection();
It is used to extend or modify the behaviour of an object at runtime.
Multiple methods are available for use by other objects. Here you can use core’s helper methods from anywhere in the application.
Allows overrides or renamed physical resources (e.g. Classes, DB tables, etc)
Mage::getModel('catalog/product') and $installer->getTable('customer/address_entity');
Thanks to contributors at: http://stackoverflow.com/questions/5041473/magento-design-patterns
Leave a comment
Welcome to my Blog
- Apache (1)
- Domain name (3)
- eCommerce (2)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (136)
- Magento admin (58)
- Magento Certification (2)
- Magento error (13)
- Magento frontend (68)
- Magento Interview (5)
- Magento2 (4)
- Mobile (1)
- MySQL (7)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (1)
- Wordpress (3)
- XML (2)