SlideShare a Scribd company logo
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Introduction and Terminology
Module Purpose/Behavior
Developing Loosely Coupled Modules with Magento
General Task of Injecting into Functionality
Hard-Coded Call Implementation
Framework
Module A Module B
Call
• Module A highly relies on
Module B
• Module B
can’t be removed
Conditional Call Implementation
Framework
Module A Module B
Call
• Module existence checking
• Module B now
can be removed
• Module A still knows about
Module B
• Rename Module B –
change Module A
• Add new module – change
Module A
if (exists(‘Module B’)) {
call(‘Module B’);
}
Module C
Maintaining the List of Dependents
Framework
Module A Module B
Register
• It’s observer pattern
• Module B
relies on Module A
• New modules can register
within the Module A without
changing anything
• Rename Module A –
change dependent
modules
Module C
Notify
Notify
Register
Publish/Subscribe Messaging Pattern
Low Modules Coupling Using Pub/Sub Pattern
Framework
Module A Module B
• Framework should take
care of coupling
• Modules don’t know about
each other
• Any module can be
removed
• New modules can
subscribe to existing
messages without
changing anything
Module C
Messages Manager
Publish
Subscribe
Call
Subscribe
Call
Magento Events
Framework
Low Modules Coupling with Magento Events
Module A
Subscribe
Module B
Call
config.xml
Config Manager
config.xml
Merged config.xml
Events Manager
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)
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Events Subscription in Configuration
• Mapping events to handling
routines
• Declaration of handlers
for each application area
<events>
<catalog_product_load_after>
<observers>
<inventory>
<class>cataloginventory/observer</class>
<method>addInventoryData</method>
</inventory>
</observers>
</catalog_product_load_after>
class Mage_CatalogInventory_Model_Observer
{
public function addInventoryData($observer)
{
// ...
}
No Events Subscription in Configuration
• Good default mapping
• Single observer class per
module
• Method name equals event
name
<config>
<global>
<events/>
</global>
<frontend>
<events/>
</frontend>
<adminhtml>
<events/>
</adminhtml>
</config>
class Mage_CatalogInventory_Model_Observer
{
public function catalog_product_load_after($observer)
{
// ...
}
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Framework
High Modules Coupling
Mage_Cron
Removing Mage_Cron breaks My_Module
My_Module
Schedule Job
Get Schedule & Run Job
Developing Loosely Coupled Modules with Magento
Framework
Low Modules Coupling Using Configuration
Mage_Cron
config.xml
My_Module
config.xml
GetSchedule
Run Job
Removing Mage_Cron doesn’t break anything
Config ManagerMerged config.xml
ScheduleJob
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
sergey.shymko@magento.com

More Related Content

PPTX
Developing Loosely Coupled Modules with Magento
PPTX
Running Magento 1.x Extension on Magento 2
PPTX
Developing loosely coupled modules with Magento
PPTX
Java modulesystem
PDF
Modules as requirement specifications
PDF
Lab 1: Modifying a module's attributes and viewing its history
PDF
Introduction to Microsoft Prism
PDF
Monolith to Modular - The devil in the dependencies
Developing Loosely Coupled Modules with Magento
Running Magento 1.x Extension on Magento 2
Developing loosely coupled modules with Magento
Java modulesystem
Modules as requirement specifications
Lab 1: Modifying a module's attributes and viewing its history
Introduction to Microsoft Prism
Monolith to Modular - The devil in the dependencies

More from Sergii Shymko (13)

PPTX
Magento 2 Changes Overview
PPTX
Magento 2 Composer for Extensions Distribution
PPTX
Black Magic of Code Generation in Magento 2
PPTX
Composer in Magento
PPTX
Magento 2 Code Migration Tool
PPTX
Magento 2 Composer for Extensions Distribution
PPT
Magento 2 Enhanced Theme/Skin Localization
PPTX
Magento Performance Toolkit
PPTX
Magento 2 View Layer Evolution
PPTX
Magento 2 Theme Localization
PPTX
Code Generation in Magento 2
PPTX
Composer for Magento 1.x and Magento 2
PPTX
Magento 1.x to Magento 2 Code Migration Tools
Magento 2 Changes Overview
Magento 2 Composer for Extensions Distribution
Black Magic of Code Generation in Magento 2
Composer in Magento
Magento 2 Code Migration Tool
Magento 2 Composer for Extensions Distribution
Magento 2 Enhanced Theme/Skin Localization
Magento Performance Toolkit
Magento 2 View Layer Evolution
Magento 2 Theme Localization
Code Generation in Magento 2
Composer for Magento 1.x and Magento 2
Magento 1.x to Magento 2 Code Migration Tools
Ad

Recently uploaded (20)

PPT
Occupational Health and Safety Management System
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
Soil Improvement Techniques Note - Rabbi
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Software Engineering and software moduleing
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
Feature types and data preprocessing steps
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
Occupational Health and Safety Management System
Exploratory_Data_Analysis_Fundamentals.pdf
Soil Improvement Techniques Note - Rabbi
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Categorization of Factors Affecting Classification Algorithms Selection
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Abrasive, erosive and cavitation wear.pdf
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Information Storage and Retrieval Techniques Unit III
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
distributed database system" (DDBS) is often used to refer to both the distri...
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Software Engineering and software moduleing
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Feature types and data preprocessing steps
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
R24 SURVEYING LAB MANUAL for civil enggi
Ad

Developing Loosely Coupled Modules with Magento

  • 6. General Task of Injecting into Functionality
  • 7. Hard-Coded Call Implementation Framework Module A Module B Call • Module A highly relies on Module B • Module B can’t be removed
  • 8. Conditional Call Implementation Framework Module A Module B Call • Module existence checking • Module B now can be removed • Module A still knows about Module B • Rename Module B – change Module A • Add new module – change Module A if (exists(‘Module B’)) { call(‘Module B’); } Module C
  • 9. Maintaining the List of Dependents Framework Module A Module B Register • It’s observer pattern • Module B relies on Module A • New modules can register within the Module A without changing anything • Rename Module A – change dependent modules Module C Notify Notify Register
  • 11. Low Modules Coupling Using Pub/Sub Pattern Framework Module A Module B • Framework should take care of coupling • Modules don’t know about each other • Any module can be removed • New modules can subscribe to existing messages without changing anything Module C Messages Manager Publish Subscribe Call Subscribe Call
  • 13. Framework Low Modules Coupling with Magento Events Module A Subscribe Module B Call config.xml Config Manager config.xml Merged config.xml Events Manager Mage::dispatchEvent
  • 14. 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)
  • 18. Events Subscription in Configuration • Mapping events to handling routines • Declaration of handlers for each application area <events> <catalog_product_load_after> <observers> <inventory> <class>cataloginventory/observer</class> <method>addInventoryData</method> </inventory> </observers> </catalog_product_load_after> class Mage_CatalogInventory_Model_Observer { public function addInventoryData($observer) { // ... }
  • 19. No Events Subscription in Configuration • Good default mapping • Single observer class per module • Method name equals event name <config> <global> <events/> </global> <frontend> <events/> </frontend> <adminhtml> <events/> </adminhtml> </config> class Mage_CatalogInventory_Model_Observer { public function catalog_product_load_after($observer) { // ... }
  • 23. Framework High Modules Coupling Mage_Cron Removing Mage_Cron breaks My_Module My_Module Schedule Job Get Schedule & Run Job
  • 25. Framework Low Modules Coupling Using Configuration Mage_Cron config.xml My_Module config.xml GetSchedule Run Job Removing Mage_Cron doesn’t break anything Config ManagerMerged config.xml ScheduleJob

Editor's Notes

  • #11: Observer OOP pattern is a subset of the publish/subscribe messaging pattern observers subscribe to the particular subjects
  • #13: OOP implementation of pub/sub pattern is the single global event manager
  • #19: Convention over Configuration
  • #20: Convention over Configuration
  • #26: Cron job scheduling through config.xml
  • #28: Let’s summarize what we have learned during this hour.