SlideShare a Scribd company logo
1 of 29
Click to edit Master title style
Ibiza, June 4th – 7th 2011
Magento Developers Paradise
Developing Loosely Coupled Modules with
Magento
Sergey Shymko
Magento 2 Team
Introduction and Terminology
• Coupling or dependency is the degree to
which each program module relies on
each one of the other modules
• Coupling measures the likelihood of a
change or fault in one module affecting
another module
Module Purpose/Behavior
• Module introduces new feature
• Module injects into existing functionality
• Module integrates with existing feature
• Module extends/overlaps existing
functionality
Magento Developers Paradise
Modules Coupling While
Injecting Into the Functionality
General Task of Injecting into Functionality
• Module A exists and already implements
the functionality
• Module B expands the Module A
• Module B should be triggered at the
specific point of the Module A execution
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 Aif (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
modulesModule C
Notify
Notify
Register
Publish/Subscribe Messaging Pattern
• Pub/sub – universal decoupling solution
– senders of messages do not program the
messages to be sent directly to specific
receivers
– subscribers express interest in messages
without knowledge of publishers
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 anythingModule C
Messages Manager
Publish
Subscribe
Call
Subscribe
Call
Magento Events
• Magento events – object-oriented
implementation of the pub/sub pattern
• Event dispatching calls – points of
integration
• Subscription through config.xml
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 Magento Events
Coupling depends on the implementation of the particular event handler
Coupling Type Description
Message coupling (low) Event doesn’t pass any data
Data coupling Simple event parameters, each is used
Stamp coupling Event data structure contains fields which may or
may not be used
Common coupling Usage of the global data registry; Accessing data
not only through methods
Content coupling (high) Not applicable to the pub/sub
Possible Improvements in Magento Events
• Strict event data types
• Convention over configuration
• Events naming convention
Strict Event Data Types
• Own event class for each unique
parameters combination
‒ Formal data structure declaration
‒ Access restriction to event data
‒ Events documentation auto-generation
Convention over Configuration
• Also known as coding by convention
• Decreasing the number of decisions that
developers need to make
• Simplicity while keeping flexibility
• Providing good defaults
Events Subscription in Configuration
• Mapping events to
handling routines
• Declaration of handlers
for each 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)
{
// ...
}
Event Naming Convention
Event Name Part Description
1. Module Name of the module, which introduces an event.
2. Layer Application layer where an event appears.
Allowed values: model, view, controller, service.
3. Entity Entity (domain) to which event has relation.
4. Action By default action should be equal to the method name,
which triggers an event.
[5. Suffix] Optional. Allowed values: before, after
lowerCamelCase event name to correspond to the method name
Magento Developers Paradise
Modules Coupling While
Integrating with Existing Feature
Sample Task – Cron Feature
• Module Mage_Cron introduces time-based
jobs scheduling feature
• Any module should be able to schedule its
jobs
Framework
High Modules Coupling
Mage_Cron
Removing Mage_Cron breaks My_Module
My_Module
Schedule Job
Get Schedule & Run Job
Magento Configuration Files
• Configuration files “merging” from all
enabled modules
• Configuration allows integration with:
– system-wide feature
– feature provided by the module
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
Configuration Usage in Magento
• Cache management
• Index management
• Product types
• Translation files
• Layout files
• …
Magento Developers Paradise
Summary
Recommendations
• Follow the low coupling principles – use
events to communicate between modules
• Extend only when no events are triggered
• Report requests for adding new events
• Don’t hesitate to trigger events in your
third-party modules and extensions
Magento Developers Paradise
Thank You!
Sergey Shymko
sergey.shymko@magento.com
Questions & Answers

More Related Content

Similar to Developing Loosely Coupled Modules with Magento

Flex modular applications using robotlegs
Flex modular applications using robotlegsFlex modular applications using robotlegs
Flex modular applications using robotlegsSaurabh Narula
 
Porting the Legacy Application to Composite Application Guidance
Porting the Legacy Application to Composite Application GuidancePorting the Legacy Application to Composite Application Guidance
Porting the Legacy Application to Composite Application GuidanceOur Community Exchange LLC
 
Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2Salesforce Developers
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxanguraju1
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10Bryan Anderson
 
Layers of Smalltalk Application
Layers of Smalltalk ApplicationLayers of Smalltalk Application
Layers of Smalltalk Applicationspeludner
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutAndoni Arroyo
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in MagentoDivante
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystemMarc Kassis
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsVolodymyr Voytyshyn
 
Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript AppsGil Fink
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?satejsahu
 
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home PageBIOVIA
 
Unit-III(Design).pptx
Unit-III(Design).pptxUnit-III(Design).pptx
Unit-III(Design).pptxFajar Baskoro
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaRainer Stropek
 

Similar to Developing Loosely Coupled Modules with Magento (20)

Flex modular applications using robotlegs
Flex modular applications using robotlegsFlex modular applications using robotlegs
Flex modular applications using robotlegs
 
Porting the Legacy Application to Composite Application Guidance
Porting the Legacy Application to Composite Application GuidancePorting the Legacy Application to Composite Application Guidance
Porting the Legacy Application to Composite Application Guidance
 
Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
Patterns In-Javascript
Patterns In-JavascriptPatterns In-Javascript
Patterns In-Javascript
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10
 
Layers of Smalltalk Application
Layers of Smalltalk ApplicationLayers of Smalltalk Application
Layers of Smalltalk Application
 
Knockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockoutKnockout implementing mvvm in java script with knockout
Knockout implementing mvvm in java script with knockout
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in Magento
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystem
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
 
Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript Apps
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?
 
Angular2 and You
Angular2 and YouAngular2 and You
Angular2 and You
 
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
 
Design pattern
Design patternDesign pattern
Design pattern
 
Unit-III(Design).pptx
Unit-III(Design).pptxUnit-III(Design).pptx
Unit-III(Design).pptx
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA Austria
 

More from Sergii Shymko

Magento 2 Changes Overview
Magento 2 Changes OverviewMagento 2 Changes Overview
Magento 2 Changes OverviewSergii Shymko
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionSergii Shymko
 
Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2Sergii Shymko
 
Magento 2 Code Migration Tool
Magento 2 Code Migration ToolMagento 2 Code Migration Tool
Magento 2 Code Migration ToolSergii Shymko
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionSergii Shymko
 
Magento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin LocalizationMagento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin LocalizationSergii Shymko
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance ToolkitSergii Shymko
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoSergii Shymko
 
Magento 2 View Layer Evolution
Magento 2 View Layer EvolutionMagento 2 View Layer Evolution
Magento 2 View Layer EvolutionSergii Shymko
 
Magento 2 Theme Localization
Magento 2 Theme LocalizationMagento 2 Theme Localization
Magento 2 Theme LocalizationSergii Shymko
 
Running Magento 1.x Extension on Magento 2
Running Magento 1.x Extension on Magento 2Running Magento 1.x Extension on Magento 2
Running Magento 1.x Extension on Magento 2Sergii Shymko
 
Code Generation in Magento 2
Code Generation in Magento 2Code Generation in Magento 2
Code Generation in Magento 2Sergii Shymko
 
Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Sergii Shymko
 
Magento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration ToolsMagento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration ToolsSergii Shymko
 

More from Sergii Shymko (15)

Magento 2 Changes Overview
Magento 2 Changes OverviewMagento 2 Changes Overview
Magento 2 Changes Overview
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
 
Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2
 
Composer in Magento
Composer in MagentoComposer in Magento
Composer in Magento
 
Magento 2 Code Migration Tool
Magento 2 Code Migration ToolMagento 2 Code Migration Tool
Magento 2 Code Migration Tool
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
 
Magento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin LocalizationMagento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin Localization
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
 
Magento 2 View Layer Evolution
Magento 2 View Layer EvolutionMagento 2 View Layer Evolution
Magento 2 View Layer Evolution
 
Magento 2 Theme Localization
Magento 2 Theme LocalizationMagento 2 Theme Localization
Magento 2 Theme Localization
 
Running Magento 1.x Extension on Magento 2
Running Magento 1.x Extension on Magento 2Running Magento 1.x Extension on Magento 2
Running Magento 1.x Extension on Magento 2
 
Code Generation in Magento 2
Code Generation in Magento 2Code Generation in Magento 2
Code Generation in Magento 2
 
Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2Composer for Magento 1.x and Magento 2
Composer for Magento 1.x and Magento 2
 
Magento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration ToolsMagento 1.x to Magento 2 Code Migration Tools
Magento 1.x to Magento 2 Code Migration Tools
 

Recently uploaded

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

Developing Loosely Coupled Modules with Magento

  • 1. Click to edit Master title style Ibiza, June 4th – 7th 2011
  • 2. Magento Developers Paradise Developing Loosely Coupled Modules with Magento Sergey Shymko Magento 2 Team
  • 3. Introduction and Terminology • Coupling or dependency is the degree to which each program module relies on each one of the other modules • Coupling measures the likelihood of a change or fault in one module affecting another module
  • 4. Module Purpose/Behavior • Module introduces new feature • Module injects into existing functionality • Module integrates with existing feature • Module extends/overlaps existing functionality
  • 5. Magento Developers Paradise Modules Coupling While Injecting Into the Functionality
  • 6. General Task of Injecting into Functionality • Module A exists and already implements the functionality • Module B expands the Module A • Module B should be triggered at the specific point of the Module A execution
  • 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 Aif (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 modulesModule C Notify Notify Register
  • 10. Publish/Subscribe Messaging Pattern • Pub/sub – universal decoupling solution – senders of messages do not program the messages to be sent directly to specific receivers – subscribers express interest in messages without knowledge of publishers
  • 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 anythingModule C Messages Manager Publish Subscribe Call Subscribe Call
  • 12. Magento Events • Magento events – object-oriented implementation of the pub/sub pattern • Event dispatching calls – points of integration • Subscription through config.xml
  • 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 Magento Events Coupling depends on the implementation of the particular event handler Coupling Type Description Message coupling (low) Event doesn’t pass any data Data coupling Simple event parameters, each is used Stamp coupling Event data structure contains fields which may or may not be used Common coupling Usage of the global data registry; Accessing data not only through methods Content coupling (high) Not applicable to the pub/sub
  • 15. Possible Improvements in Magento Events • Strict event data types • Convention over configuration • Events naming convention
  • 16. Strict Event Data Types • Own event class for each unique parameters combination ‒ Formal data structure declaration ‒ Access restriction to event data ‒ Events documentation auto-generation
  • 17. Convention over Configuration • Also known as coding by convention • Decreasing the number of decisions that developers need to make • Simplicity while keeping flexibility • Providing good defaults
  • 18. Events Subscription in Configuration • Mapping events to handling routines • Declaration of handlers for each 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) { // ... }
  • 20. Event Naming Convention Event Name Part Description 1. Module Name of the module, which introduces an event. 2. Layer Application layer where an event appears. Allowed values: model, view, controller, service. 3. Entity Entity (domain) to which event has relation. 4. Action By default action should be equal to the method name, which triggers an event. [5. Suffix] Optional. Allowed values: before, after lowerCamelCase event name to correspond to the method name
  • 21. Magento Developers Paradise Modules Coupling While Integrating with Existing Feature
  • 22. Sample Task – Cron Feature • Module Mage_Cron introduces time-based jobs scheduling feature • Any module should be able to schedule its jobs
  • 23. Framework High Modules Coupling Mage_Cron Removing Mage_Cron breaks My_Module My_Module Schedule Job Get Schedule & Run Job
  • 24. Magento Configuration Files • Configuration files “merging” from all enabled modules • Configuration allows integration with: – system-wide feature – feature provided by the module
  • 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
  • 26. Configuration Usage in Magento • Cache management • Index management • Product types • Translation files • Layout files • …
  • 28. Recommendations • Follow the low coupling principles – use events to communicate between modules • Extend only when no events are triggered • Report requests for adding new events • Don’t hesitate to trigger events in your third-party modules and extensions
  • 29. Magento Developers Paradise Thank You! Sergey Shymko sergey.shymko@magento.com Questions & Answers

Editor's Notes

  1. First of all, let me introduce myself. My name is Sergey Shymko. I’m the lead PHP developer in the Magento. I started in Magento as a Core team member, then moved to the Support department. And currently I participate in the Magento 2 project. The new one hour we’re going to discuss very interesting and difficult topic. It’s “How to develop low coupled modules with Magento”. I don’t want to stop on explaining the importance of the topic. I’m sure all you already know that. Usually “good software design” means exactly low coupling between the components of the system. Low coupling makes software maintainable, allows to grow functionality, while keeping the development cost reasonable, and so on, and so on. All you know that. So, what is coupling, can anybody help me to answer this question? Anyone?
  2. I’m sure that all we have intuitive filling what is coupling. But, to be more specific let’s clarify the terminology.
  3. Since we’re talking about modules. In general, what is the purpose of any module? Module always ships the piece of functionality. It can be the completely new feature that doesn’t interact with the other modules in the system. Any combination of the items
  4. Observer OOP pattern is a subset of the publish/subscribe messaging pattern observers subscribe to the particular subjects
  5. OOP implementation of pub/sub pattern is the single global event manager
  6. Convention over Configuration
  7. Convention over Configuration
  8. Cron job scheduling through config.xml
  9. Let’s summarize what we have learned during this hour.