Introduction and Terminology
Module Purpose/Behavior
General Task of Injecting into Functionality
Hard-Coded Call Implementation Framework                                            •   Module A highly relies on         ...
Conditional Call Implementation Framework                                              •   Module existence checking      ...
Maintaining the List of Dependents Framework                                                  •   It’s observer pattern   ...
Publish/Subscribe Messaging Pattern
Low Modules Coupling Using Pub/Sub Pattern Framework                                                                    • ...
Magento Events
Low Modules Coupling with Magento Events        Framework                                 Merged config.xml       Config M...
Achieved Coupling with Events Actual coupling depends on the implementation of the particular event handler:   Message cou...
Events Subscription in Configuration <events>     <catalog_product_load_after>                            •   Mapping even...
No Events Subscription in Configuration <config>         <global>                                            •   Good defa...
High Modules Coupling        Framework                    Mage_Cron                            My_Module                  ...
Low Modules Coupling Using Configuration         Framework                                  Merged config.xml      Config ...
sergey.shymko@magento.com
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Developing loosely coupled modules with Magento
Upcoming SlideShare
Loading in …5
×

Developing loosely coupled modules with Magento

1,064 views

Published on

Magento configuration files are a solid way to integrate with a module’s features. Application developers will gain insight into the different kinds of module dependencies and their impact on applications. We’ll look at Magento’s events model as an example to illustrate how to publish and subscribe messaging patterns as a universal decoupling mechanism.

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,064
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Observer OOP pattern is a subset of the publish/subscribe messaging patternobservers subscribe to the particular subjects
  • OOP implementation of pub/sub pattern is the single global event manager
  • Convention over Configuration
  • Convention over Configuration
  • Cron job scheduling through config.xml
  • Let’s summarize what we have learned during this hour.
  • Developing loosely coupled modules with Magento

    1. 1. Introduction and Terminology
    2. 2. Module Purpose/Behavior
    3. 3. General Task of Injecting into Functionality
    4. 4. Hard-Coded Call Implementation Framework • Module A highly relies on Module B • Module B can’t be removed Module A Module B Call
    5. 5. Conditional Call Implementation Framework • Module existence checking • Module B now can be removed • Module A still knows about Module B Module A Module B • Rename Module B – change Module A • Add new module – change Call Module A Module C if (exists(‘Module B’)) { call(‘Module B’); }
    6. 6. Maintaining the List of Dependents Framework • It’s observer pattern • Module B relies on Module A • New modules can register within the Module A without Module A Module B changing anything Register • Rename Module A – change dependent modules Notify Module C Notify Register
    7. 7. Publish/Subscribe Messaging Pattern
    8. 8. Low Modules Coupling Using Pub/Sub Pattern Framework • Framework should take Messages Manager care of coupling • Modules don’t know about each other Subscribe Subscribe • Any module can be Publish Module A Module B removed • New modules can subscribe to existing messages without changing anything Call Module C Call
    9. 9. Magento Events
    10. 10. Low Modules Coupling with Magento Events Framework Merged config.xml Config Manager Events Manager Subscribe Module A Module B config.xml config.xml Call Mage::dispatchEvent
    11. 11. Achieved Coupling with Events Actual coupling depends on the implementation of the particular event handler: Message coupling (low) Data coupling Stamp coupling Common coupling … Content coupling (high)
    12. 12. Events Subscription in Configuration <events> <catalog_product_load_after> • Mapping events to handling <observers> routines <inventory> • Declaration of handlers <class>cataloginventory/observer</class> <method>addInventoryData</method> for each application area </inventory> </observers> </catalog_product_load_after> class Mage_CatalogInventory_Model_Observer { public function addInventoryData($observer) { // ... }
    13. 13. No Events Subscription in Configuration <config> <global> • Good default mapping <events/> • Single observer class per </global> module <frontend> <events/> • Method name equals event </frontend> name <adminhtml> <events/> </adminhtml> </config> class Mage_CatalogInventory_Model_Observer { public function catalog_product_load_after($observer) { // ... }
    14. 14. High Modules Coupling Framework Mage_Cron My_Module Schedule Job Get Schedule & Run Job Removing Mage_Cron breaks My_Module
    15. 15. Low Modules Coupling Using Configuration Framework Merged config.xml Config Manager Get Schedule Schedule Job Mage_Cron My_Module config.xml config.xml Run Job Removing Mage_Cron doesn’t break anything
    16. 16. sergey.shymko@magento.com

    ×