• Save
Developing loosely coupled modules with Magento
Upcoming SlideShare
Loading in...5
×
 

Developing loosely coupled modules with Magento

on

  • 1,027 views

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 ...

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.

Statistics

Views

Total Views
1,027
Slideshare-icon Views on SlideShare
1,027
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 Developing loosely coupled modules with Magento Presentation Transcript

  • Introduction and Terminology
  • Module Purpose/Behavior
  • General Task of Injecting into Functionality
  • Hard-Coded Call Implementation Framework • Module A highly relies on Module B • Module B can’t be removed Module A Module B Call
  • 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’); }
  • 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
  • Publish/Subscribe Messaging Pattern
  • 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
  • Magento Events
  • 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
  • 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)
  • 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) { // ... }
  • 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) { // ... }
  • High Modules Coupling Framework Mage_Cron My_Module Schedule Job Get Schedule & Run Job Removing Mage_Cron breaks My_Module
  • 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
  • sergey.shymko@magento.com