SlideShare a Scribd company logo
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 Guidance
Our 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 2
Salesforce Developers
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju1
 
Patterns In-Javascript
Patterns In-JavascriptPatterns In-Javascript
Patterns In-Javascript
Mindfire Solutions
 
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
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
Betclic Everest Group Tech Team
 
Design patterns in Magento
Design patterns in MagentoDesign patterns in Magento
Design patterns in Magento
Divante
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
Ivano Malavolta
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystem
Marc Kassis
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
Volodymyr Voytyshyn
 
Building Scalable JavaScript Apps
Building Scalable JavaScript AppsBuilding Scalable JavaScript Apps
Building Scalable JavaScript Apps
Gil 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
 
Angular2 and You
Angular2 and YouAngular2 and You
Angular2 and You
Joseph Jorden
 
(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
BIOVIA
 
Design pattern
Design patternDesign pattern
Design pattern
Shreyance Jain
 
Unit-III(Design).pptx
Unit-III(Design).pptxUnit-III(Design).pptx
Unit-III(Design).pptx
Fajar 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 Austria
Rainer 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 Overview
Sergii Shymko
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
Sergii 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 2
Sergii Shymko
 
Composer in Magento
Composer in MagentoComposer in Magento
Composer in Magento
Sergii Shymko
 
Magento 2 Code Migration Tool
Magento 2 Code Migration ToolMagento 2 Code Migration Tool
Magento 2 Code Migration Tool
Sergii Shymko
 
Magento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions DistributionMagento 2 Composer for Extensions Distribution
Magento 2 Composer for Extensions Distribution
Sergii Shymko
 
Magento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin LocalizationMagento 2 Enhanced Theme/Skin Localization
Magento 2 Enhanced Theme/Skin Localization
Sergii Shymko
 
Magento Performance Toolkit
Magento Performance ToolkitMagento Performance Toolkit
Magento Performance Toolkit
Sergii Shymko
 
Developing Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with MagentoDeveloping Loosely Coupled Modules with Magento
Developing Loosely Coupled Modules with Magento
Sergii Shymko
 
Magento 2 View Layer Evolution
Magento 2 View Layer EvolutionMagento 2 View Layer Evolution
Magento 2 View Layer Evolution
Sergii Shymko
 
Magento 2 Theme Localization
Magento 2 Theme LocalizationMagento 2 Theme Localization
Magento 2 Theme Localization
Sergii 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 2
Sergii Shymko
 
Code Generation in Magento 2
Code Generation in Magento 2Code Generation in Magento 2
Code Generation in Magento 2
Sergii 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 2
Sergii 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 Tools
Sergii 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

PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 

Recently uploaded (20)

PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 

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.