Part 1: Fundamentals

Sunday 26 January 2014

Magento is established based on Principles of Object-Oriented Programming on Zend Framework with MVC architecture. It uses Event-Driven Architecture (EDA) to manage events. In this part, we will talk about: 1. Describe and apply basic principles and processes of Object Oriented Programming (OOP) and Model-View-Controller (MVC) to build Magento websites 2. Identify and describe principles of Event-Driven Architecture (EDA) 3. Sample questions & answers I - Describe and apply basic principles and processes of Object Oriented Programming (OOP) and Model-View-Controller (MVC) to build Magento websites 1. Object Oriented Programming OOP  Abstraction Use function/class without knowing exactly how that function/class accomplishes its tasks. What we concern is parameters sent to it and its returned value. A typical example is function _init() in class Mage_Core_Model_Abstract, this function will be executed to define with which table in CSDL the model will work. - Inherited class of Abstract class is just the instance of the abstract class. - Calling abstract function requires its instance function, which means in the children class you must rewrite this function.  Encapsulation Objects are encapsulated. When changing data, you must go through functions to work with that object. In other words, a product cannot know information of another product. The common thing between the 2 products is the method working with them.  Polymorphism Object instances of a same class are different. For example, products of different types (simple/grouped/…) have different price calculated methods.  Inheritance Inheritance is exploited in Magento, especially Varien_Object class which is inherited by many classes in Magento. (Function setData/getData is inherited from Varien_Object). 2. Model-View-Controller MVC  Model Model is the classes providing data, service related to data and business logic. This class works directly with data and provides data for other elements. In a module, these classes are contained in Model folder.  View View is the classes which define data presented method (not update data). These classes are contained in the folder Block of module.  Controller Controller is the classes which control application stream. They receive input which is requirement of users through HTTP request, transfer those requests to the classes which process the requests directly. From the link, Router will get to Controller which controls that link. In Magento module, these classes are contained in controller folder. II - Identify and describe principles of Event-Driven Architecture (EDA) 1. Event-Driven Architecture 2. Magento event  Event Listener & Generator: When an event happens, this element will Listen the event, create signals of that event and send that signal to Event Engine.  Event Engine: When receiving signals of the event, this element will send them to factor Client to process that event.  Client: When receiving signals of the event, this element will execute steps to respond to that event.
 

Contact Form

Name

Email *

Message *

Most Reading