slide1 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Ibiza, June 4 th – 7 th 2011 PowerPoint Presentation
Download Presentation
Ibiza, June 4 th – 7 th 2011

Loading in 2 Seconds...

play fullscreen
1 / 29

Ibiza, June 4 th – 7 th 2011 - PowerPoint PPT Presentation


  • 119 Views
  • Uploaded on

Ibiza, June 4 th – 7 th 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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Ibiza, June 4 th – 7 th 2011' - idalia


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide2

Magento Developers Paradise

Developing Loosely Coupled Modules with Magento

Sergey Shymko

Magento 2 Team

slide3

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
slide4

Module Purpose/Behavior

  • Module introduces new feature
  • Module injects into existing functionality
  • Module integrates with existing feature
  • Module extends/overlaps existing functionality
slide5

Magento Developers Paradise

Modules Coupling WhileInjecting Into the Functionality

slide6

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
slide7

Hard-Coded Call Implementation

Framework

  • Module A highly relies on Module B
  • Module Bcan’t be removed

Module A

Module B

Call

slide8

Conditional Call Implementation

Framework

  • Module existence checking
  • Module B nowcan be removed
  • Module A still knows about Module B
  • Rename Module B – change Module A
  • Add new module – change Module A

Module A

Module B

Call

if (exists(‘Module B’)) {

call(‘Module B’);

}

Module C

slide9

Maintaining the List of Dependents

Framework

  • It’s observer pattern
  • Module Brelies on Module A
  • New modules can register within the Module A without changing anything
  • Rename Module A – change dependent modules

Module A

Module B

Register

Notify

Module C

Notify

Register

slide10

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
slide11

Low Modules Coupling Using Pub/Sub Pattern

Framework

Messages Manager

  • 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

Subscribe

Subscribe

Publish

Module A

Module B

Call

Module C

Call

slide12

Magento Events

  • Magento events – object-oriented implementation of the pub/sub pattern
  • Event dispatching calls – points of integration
  • Subscription through config.xml
slide13

Low Modules Coupling with Magento Events

Framework

Config Manager

Merged config.xml

Events Manager

Module A

Module B

Subscribe

config.xml

config.xml

Call

Mage::dispatchEvent

slide14

Achieved Coupling with Magento Events

  • Coupling depends on the implementation of the particular event handler
slide15

Possible Improvements in Magento Events

  • Strict event data types
  • Convention over configuration
  • Events naming convention
slide16

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
slide17

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
slide18

Events Subscription in Configuration

<events>

<catalog_product_load_after>

<observers>

<inventory>

<class>cataloginventory/observer</class>

<method>addInventoryData</method>

</inventory>

</observers>

</catalog_product_load_after>

  • Mapping events to handling routines
  • Declaration of handlersfor each area

classMage_CatalogInventory_Model_Observer

{

public function addInventoryData($observer)

{

// ...

}

slide19

No Events Subscription in Configuration

<config>

<global>

<events/>

</global>

<frontend>

<events/>

</frontend>

<adminhtml>

<events/>

</adminhtml>

</config>

  • Good default mapping
  • Single observer class per module
  • Method name equals event name

classMage_CatalogInventory_Model_Observer

{

public function catalog_product_load_after($observer)

{

// ...

}

slide20

Event Naming Convention

  • lowerCamelCase event name to correspond to the method name
slide21

Magento Developers Paradise

Modules Coupling While

Integrating with Existing Feature

slide22

Sample Task – Cron Feature

  • Module Mage_Cron introduces time-based jobs scheduling feature
  • Any module should be able to schedule its jobs
slide23

High Modules Coupling

Framework

Mage_Cron

My_Module

Schedule Job

Get Schedule & Run Job

Removing Mage_Cron breaks My_Module

slide24

Magento Configuration Files

  • Configuration files “merging” from all enabled modules
  • Configuration allows integration with:
    • system-wide feature
    • feature provided by the module
slide25

Low Modules Coupling Using Configuration

Framework

Config Manager

Merged config.xml

Mage_Cron

My_Module

Get Schedule

Schedule Job

config.xml

config.xml

Run Job

Removing Mage_Cron doesn’t break anything

slide26

Configuration Usage in Magento

  • Cache management
  • Index management
  • Product types
  • Translation files
  • Layout files
slide28

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
slide29

Magento Developers Paradise

Thank You!

Questions & Answers

Sergey Shymko

sergey.shymko@magento.com