Topic 1 – Part 1: Fundamentals
Hello every one,
You must have heard the hottest news in Magento Community: Magento Certificate exam! Are you going to join that test? If so, don’t miss the huge and comprehensive resource of Magento brought you by us. Keep your eyes on our Blog every Friday for the latest posts. We will cover the whole 10 content areas which are in the Magento test form, started with the first chapter Basics this week.
Magento is built based on Principles of Object-Oriented Programming on Zend Framework with MVC architecture and use Event-Driven Architecture (EDA) to manage events.
In this post, we will talk about:
- Describe and apply basic principles and processes of Object Oriented Programming (OOP) and Model-View-Controller (MVC) to build Magento websites
- Identify and describe the principles of Event-Driven Architecture (EDA)
- 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
Use function/class without knowing exactly how that function/class accomplishes its tasks. What we care 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 the model will work with which table in CSDL.
– 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.
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 between the 2 products is the method working with them.
Object instances of a same class are different. For example, products of different types (simple/grouped/…) have different price calculated method.
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 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 is the classes which define data presented method (not update data). These classes are contained in the folder Block of module.
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 the principles of Event-Driven Architecture (EDA)
1. Event-Driven Architecture
- 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.
2. Mangento Event
- Event Listener & Generator: is function Mage::dispatchEvent().
- Event Engine: function Mage_Core_Model_App::dispatchEvent() reads config (xml) and send signals to Client (by calling function _callObserverMethod()).
- Client: are functions of modules that catch the event.
1. What is static function?
Static function is silent function of a class, which is stored in the memory space of a class (not objects).
2. The order of event when several modules catch the same event?
Order of event: Which module is first loaded will get the signals before others. The order of loading module depends on the name of module and configure of module:
– Module depends on another module will be loaded later than the module it depends.
– Order of loading configure of module is as below:
*Mage_All.xml will be loaded first, module configure in this file will be loaded first
And file.xml will be loaded according to the order of the file’s name.
Somehow basics knowledge is more difficult to understand than others, do you think so?
We also contribute great content of Magento Download for FREE (all versions)
DON'T MISS THE CHANCE!