SlideShare a Scribd company logo
© 2016 Magento, Inc. Page | 1
Backward Compatibility
Developer’s guide
Miniailo Igor,
Magento 2 Architect
© 2016 Magento, Inc. Page | 2
© 2016 Magento, Inc. Page | 3
© 2016 Magento, Inc. Page | 4
© 2016 Magento, Inc. Page | 5
© 2016 Magento, Inc. Page | 6
© 2016 Magento, Inc. Page | 7
• Magento 2 Technical Guidelines
• Versioning
• Backward Compatibility Development
Guide
© 2016 Magento, Inc. Page | 8
Why does BC matter?
For merchants, the process
must be cost-effective, while
developers want their
extensions to be forward-
compatible for as long as
possible.
© 2016 Magento, Inc. Page | 9
Does Magento have a lot of bugs?
Are these bugs annoying for Magento
developers?
© 2016 Magento, Inc. Page | 10
Keep Magento backwards compatible vs.
fixing its flaws?
© 2016 Magento, Inc. Page | 11
We MUST do BOTH
© 2016 Magento, Inc. Page | 12
Backward Compatible Fix
*it works (most of the time), but code quality
is far from good enough
© 2016 Magento, Inc. Page | 13
Backward compatibility (BC)
policy for Magento code
© 2016 Magento, Inc. Page | 14
Semantic Versioning
Version numbers are in the format
MAJOR.MINOR.PATCH, where:
– MAJOR indicates incompatible API changes
– MINOR indicates backward-compatible
functionality has been added
– PATCH indicates backward-compatible bug
fixes
© 2016 Magento, Inc. Page | 15
The backward compatibility policy
applies to PHP code annotated with
@api
© 2016 Magento, Inc. Page | 16
Public and Private code
© 2016 Magento, Inc. Page | 17
Public vs Private code
Private code is not supposed to
be used by third party modules,
so, in most cases, its
modifications will only trigger
PATCH version bumps.
Changes in public code always
trigger MINOR or MAJOR
version bumps.
© 2016 Magento, Inc. Page | 18
What examples of Public code Magento has?
• PHP Interface (marked with @api)
• PHP Class (marked with @api)
• Javascript Interface (marked with @api)
• Javascript Class (marked with @api)
• Virtual Type (marked with @api)
• URL paths
• Console commands and their arguments
• Less Variables & Mixins
• Message queue topics and their data types
• UI component declarations
• Layout handles declared by modules
• Events triggered by component (both static dynamic)
• Schema of configuration types introduced by module
• Structure of System Configuration fields used by module
© 2016 Magento, Inc. Page | 19
API vs SPI (Extension Points)
A PHP Interface in Magento can be used several ways by the core
product and extension developers.
• As an API. An interface is called by PHP code.
• As a Service Provider Interface (SPI). An interface can
be implemented, allowing code to provide functionality to
the platform.
• As both. APIs and SPIs are not mutually exclusive.
Therefore, we do not distinguish them separately. SPIs
are annotated the same as APIs.
© 2016 Magento, Inc. Page | 20
Who decides whether interface/class belong to API or SPI?
YOU
© 2016 Magento, Inc. Page | 21
Dependency Rules API
If a module uses (calls) an API, it should be dependent on the MAJOR
version.
API dependency example
{
...
"require": {
"magento/module-customer": "~100.0", // (>=100.0 <101.0.0)
},
...
}
© 2016 Magento, Inc. Page | 22
Dependency Rules SPI
If a module implements an API/SPI, it should be dependent on the
MAJOR+MINOR version.
SPI dependency example
{
...
"require": {
"magento/module-customer": "~100.0.0", // (>=100.0.0 <100.1.0)
},
...
}
© 2016 Magento, Inc. Page | 23
http://devdocs.magento.com/guides/v2.1/release-notes/backward-
incompatible-changes-2.1.html
© 2016 Magento, Inc. Page | 24
What keeps us from making mistakes?
To minimize this risk we have developed a tool Semantic
Version Checker Tool that analyzes two code bases and
determines what part of the version need updating
(MAJOR, MINOR, PATCH). As part of the delivery process,
we must run this tool and use the results for input to the
Version Setter tool.
© 2016 Magento, Inc. Page | 25
Prohibited Code Changes
© 2016 Magento, Inc. Page | 26
• Interface/class removal
• Public & protected method removal
• Introduction of a method to a class or
interface
PHP - Prohibited Code Changes
© 2016 Magento, Inc. Page | 27
PHP - Prohibited Code Changes
• Static function removal
• Parameter addition in public methods
• Parameter addition in protected
methods
© 2016 Magento, Inc. Page | 28
PHP - Prohibited Code Changes
• Method argument type modification
• Modification of types of thrown
exceptions (unless a new exception is
a subtype of the old one)
• Constructor modification
© 2016 Magento, Inc. Page | 29
class ExistingClass
{
/**
* @var NewDependencyInterface $newDependency
*/
private $newDependency;
public function __construct(
OldDependencyIntreface $oldDependency,
$oldRequiredConstructorParameter,
$oldOptinalConstructorParameter = null,
NewDependencyInterface $newDependency = null
) {
...
$this>newDependency = $newDependency ?: MagentoFrameworkAppObjectManager::getInstance()
->get(NewDependencyInterface::class);
...
}
public function existingFunction() {
// Existing functionality
...
// Use $this->newDependency wherever the new dependency is needed
...
}
}
© 2016 Magento, Inc. Page | 30
The main rule is that backwards compatibility
is more important than niceness and effort of
the implementation.
© 2016 Magento, Inc. Page | 31
Do all backward
compatible fixes look
ugly because we are not
allowed to make
refactoring?
© 2016 Magento, Inc. Page | 32
Coupling Between Objects Reaches Its Limit with
a New Dependency
© 2016 Magento, Inc. Page | 33
We MUST do continuous Refactoring!
Backward Compatibility should not be an excuse
for not doing refactoring!
© 2016 Magento, Inc. Page | 34
This is how Backward
Compatible fix should
look like
© 2016 Magento, Inc. Page | 35
Q & A
@iminyaylo

More Related Content

PPTX
Backwards Compatibility Developers Guide. #MM17NL
PPTX
Backward Compatibility Developer's Guide in Magento 2
PPTX
Magento2.3 API Functional Testing
PPTX
Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...
PPTX
Igor Miniailo - Magento 2 API Design Best Practices
PPTX
Multi Source Inventory (MSI) in Magento 2
PDF
Mli 2017 technical EQP & marketplace
PPTX
Magento Function Testing Framework - Intro and Overview
Backwards Compatibility Developers Guide. #MM17NL
Backward Compatibility Developer's Guide in Magento 2
Magento2.3 API Functional Testing
Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...
Igor Miniailo - Magento 2 API Design Best Practices
Multi Source Inventory (MSI) in Magento 2
Mli 2017 technical EQP & marketplace
Magento Function Testing Framework - Intro and Overview

What's hot (20)

PPTX
Magento 2 Declarative Schema
PDF
Mli 2017 technical backward compatibility
PPTX
Multi-Source Inventory. Imagine. Las Vegas. 2018
PDF
Mli 2017 technical powering tomorrow_2.2
PPTX
Architecture and workflow of Multi-Source Inventory
PDF
Outlook on Magento 2
PPTX
Testing in Magento 2
PPTX
Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
PDF
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
PDF
Org-dependent Unlocked Packages for ISVs
PPTX
Backward Compatibility Developer's Guide Webinar
PPTX
Richmond MuleSoft Meetup 2021-08-18
PPTX
Dare to Share Magento Community Engineering
PPTX
Manchester Meetup #3
PDF
Mule soft meetups-24012020
PDF
APIs in a .NET World
DOCX
Wmq wmb dist migration v1 030310
PDF
API Modeling Framework: a toolbox ofr API specs. Gluecon 2017
PPTX
Mumbai MuleSoft Meetup #19 - Anypoint monitoring and MQ Integrations
Magento 2 Declarative Schema
Mli 2017 technical backward compatibility
Multi-Source Inventory. Imagine. Las Vegas. 2018
Mli 2017 technical powering tomorrow_2.2
Architecture and workflow of Multi-Source Inventory
Outlook on Magento 2
Testing in Magento 2
Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Org-dependent Unlocked Packages for ISVs
Backward Compatibility Developer's Guide Webinar
Richmond MuleSoft Meetup 2021-08-18
Dare to Share Magento Community Engineering
Manchester Meetup #3
Mule soft meetups-24012020
APIs in a .NET World
Wmq wmb dist migration v1 030310
API Modeling Framework: a toolbox ofr API specs. Gluecon 2017
Mumbai MuleSoft Meetup #19 - Anypoint monitoring and MQ Integrations
Ad

Similar to Backward Compatibility Developer's Guide in Magento 2. #MM17CZ (20)

PPTX
API design best practices
PPTX
API Design Best Practices by Igor Miniailo
PPTX
Chernivtsi Magento Meetup&Contribution day. Miniailo.I.
PPTX
MageConf 2017, Design API Best Practices
PDF
Oleksii Korshenko - Magento 2 Backwards Compatible Policy
PPTX
Magento Technical guidelines
PPTX
Applying Code Customizations to Magento 2
PDF
Zepplin_Pronko_Magento_Festival Hall 1_Final
PDF
Magento 2 Backend Development Essentials
PDF
Chernivtsi Magento Meetup&Contribution day. Naida V.
PPT
Meet Magento Belarus - Elena Leonova
PDF
Макс Екатериненко - Meet Magento Ukraine - Magento 2 Overview
PDF
Magento 2 Seminar - Roger Keulen - Machine learning
PDF
Mli 2017 technical intro to magento 2
PDF
Api in magento 2
PPT
Meet Magento Belarus - Magento2: What to expect and when? - Elena Leonova
PDF
Magento Meetup Mancheter with PushON: Elena Leonova
PPTX
Advent of magento2
PDF
Magento 2 Development for PHP Developers
PPTX
Max Yekaterynenko: Magento 2 overview
API design best practices
API Design Best Practices by Igor Miniailo
Chernivtsi Magento Meetup&Contribution day. Miniailo.I.
MageConf 2017, Design API Best Practices
Oleksii Korshenko - Magento 2 Backwards Compatible Policy
Magento Technical guidelines
Applying Code Customizations to Magento 2
Zepplin_Pronko_Magento_Festival Hall 1_Final
Magento 2 Backend Development Essentials
Chernivtsi Magento Meetup&Contribution day. Naida V.
Meet Magento Belarus - Elena Leonova
Макс Екатериненко - Meet Magento Ukraine - Magento 2 Overview
Magento 2 Seminar - Roger Keulen - Machine learning
Mli 2017 technical intro to magento 2
Api in magento 2
Meet Magento Belarus - Magento2: What to expect and when? - Elena Leonova
Magento Meetup Mancheter with PushON: Elena Leonova
Advent of magento2
Magento 2 Development for PHP Developers
Max Yekaterynenko: Magento 2 overview
Ad

More from Igor Miniailo (11)

PPTX
Extensibility of Magento, the look into the future
PPTX
Magento Storefront architecture
PPTX
Something Architecture
PPTX
A long way from Monolith to Service Isolated Architecture #MM19NL
PPTX
The long way from Monolith to Microservices
PPTX
CQRS and Event-Sourcing in Magento2 by examples of MSI
PPTX
Magento Multi-Source Inventory (MSI)
PPTX
Magento Developer Talk. Microservice Architecture and Actor Model
PPTX
Modular development in Magento 2
PPTX
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
PPTX
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Extensibility of Magento, the look into the future
Magento Storefront architecture
Something Architecture
A long way from Monolith to Service Isolated Architecture #MM19NL
The long way from Monolith to Microservices
CQRS and Event-Sourcing in Magento2 by examples of MSI
Magento Multi-Source Inventory (MSI)
Magento Developer Talk. Microservice Architecture and Actor Model
Modular development in Magento 2
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет

Recently uploaded (20)

PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Construction Project Organization Group 2.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Geodesy 1.pptx...............................................
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Well-logging-methods_new................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Digital Logic Computer Design lecture notes
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Lecture Notes Electrical Wiring System Components
PPT
Mechanical Engineering MATERIALS Selection
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Construction Project Organization Group 2.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
R24 SURVEYING LAB MANUAL for civil enggi
Geodesy 1.pptx...............................................
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Operating System & Kernel Study Guide-1 - converted.pdf
Well-logging-methods_new................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Foundation to blockchain - A guide to Blockchain Tech
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Digital Logic Computer Design lecture notes
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Lecture Notes Electrical Wiring System Components
Mechanical Engineering MATERIALS Selection

Backward Compatibility Developer's Guide in Magento 2. #MM17CZ

  • 1. © 2016 Magento, Inc. Page | 1 Backward Compatibility Developer’s guide Miniailo Igor, Magento 2 Architect
  • 2. © 2016 Magento, Inc. Page | 2
  • 3. © 2016 Magento, Inc. Page | 3
  • 4. © 2016 Magento, Inc. Page | 4
  • 5. © 2016 Magento, Inc. Page | 5
  • 6. © 2016 Magento, Inc. Page | 6
  • 7. © 2016 Magento, Inc. Page | 7 • Magento 2 Technical Guidelines • Versioning • Backward Compatibility Development Guide
  • 8. © 2016 Magento, Inc. Page | 8 Why does BC matter? For merchants, the process must be cost-effective, while developers want their extensions to be forward- compatible for as long as possible.
  • 9. © 2016 Magento, Inc. Page | 9 Does Magento have a lot of bugs? Are these bugs annoying for Magento developers?
  • 10. © 2016 Magento, Inc. Page | 10 Keep Magento backwards compatible vs. fixing its flaws?
  • 11. © 2016 Magento, Inc. Page | 11 We MUST do BOTH
  • 12. © 2016 Magento, Inc. Page | 12 Backward Compatible Fix *it works (most of the time), but code quality is far from good enough
  • 13. © 2016 Magento, Inc. Page | 13 Backward compatibility (BC) policy for Magento code
  • 14. © 2016 Magento, Inc. Page | 14 Semantic Versioning Version numbers are in the format MAJOR.MINOR.PATCH, where: – MAJOR indicates incompatible API changes – MINOR indicates backward-compatible functionality has been added – PATCH indicates backward-compatible bug fixes
  • 15. © 2016 Magento, Inc. Page | 15 The backward compatibility policy applies to PHP code annotated with @api
  • 16. © 2016 Magento, Inc. Page | 16 Public and Private code
  • 17. © 2016 Magento, Inc. Page | 17 Public vs Private code Private code is not supposed to be used by third party modules, so, in most cases, its modifications will only trigger PATCH version bumps. Changes in public code always trigger MINOR or MAJOR version bumps.
  • 18. © 2016 Magento, Inc. Page | 18 What examples of Public code Magento has? • PHP Interface (marked with @api) • PHP Class (marked with @api) • Javascript Interface (marked with @api) • Javascript Class (marked with @api) • Virtual Type (marked with @api) • URL paths • Console commands and their arguments • Less Variables & Mixins • Message queue topics and their data types • UI component declarations • Layout handles declared by modules • Events triggered by component (both static dynamic) • Schema of configuration types introduced by module • Structure of System Configuration fields used by module
  • 19. © 2016 Magento, Inc. Page | 19 API vs SPI (Extension Points) A PHP Interface in Magento can be used several ways by the core product and extension developers. • As an API. An interface is called by PHP code. • As a Service Provider Interface (SPI). An interface can be implemented, allowing code to provide functionality to the platform. • As both. APIs and SPIs are not mutually exclusive. Therefore, we do not distinguish them separately. SPIs are annotated the same as APIs.
  • 20. © 2016 Magento, Inc. Page | 20 Who decides whether interface/class belong to API or SPI? YOU
  • 21. © 2016 Magento, Inc. Page | 21 Dependency Rules API If a module uses (calls) an API, it should be dependent on the MAJOR version. API dependency example { ... "require": { "magento/module-customer": "~100.0", // (>=100.0 <101.0.0) }, ... }
  • 22. © 2016 Magento, Inc. Page | 22 Dependency Rules SPI If a module implements an API/SPI, it should be dependent on the MAJOR+MINOR version. SPI dependency example { ... "require": { "magento/module-customer": "~100.0.0", // (>=100.0.0 <100.1.0) }, ... }
  • 23. © 2016 Magento, Inc. Page | 23 http://devdocs.magento.com/guides/v2.1/release-notes/backward- incompatible-changes-2.1.html
  • 24. © 2016 Magento, Inc. Page | 24 What keeps us from making mistakes? To minimize this risk we have developed a tool Semantic Version Checker Tool that analyzes two code bases and determines what part of the version need updating (MAJOR, MINOR, PATCH). As part of the delivery process, we must run this tool and use the results for input to the Version Setter tool.
  • 25. © 2016 Magento, Inc. Page | 25 Prohibited Code Changes
  • 26. © 2016 Magento, Inc. Page | 26 • Interface/class removal • Public & protected method removal • Introduction of a method to a class or interface PHP - Prohibited Code Changes
  • 27. © 2016 Magento, Inc. Page | 27 PHP - Prohibited Code Changes • Static function removal • Parameter addition in public methods • Parameter addition in protected methods
  • 28. © 2016 Magento, Inc. Page | 28 PHP - Prohibited Code Changes • Method argument type modification • Modification of types of thrown exceptions (unless a new exception is a subtype of the old one) • Constructor modification
  • 29. © 2016 Magento, Inc. Page | 29 class ExistingClass { /** * @var NewDependencyInterface $newDependency */ private $newDependency; public function __construct( OldDependencyIntreface $oldDependency, $oldRequiredConstructorParameter, $oldOptinalConstructorParameter = null, NewDependencyInterface $newDependency = null ) { ... $this>newDependency = $newDependency ?: MagentoFrameworkAppObjectManager::getInstance() ->get(NewDependencyInterface::class); ... } public function existingFunction() { // Existing functionality ... // Use $this->newDependency wherever the new dependency is needed ... } }
  • 30. © 2016 Magento, Inc. Page | 30 The main rule is that backwards compatibility is more important than niceness and effort of the implementation.
  • 31. © 2016 Magento, Inc. Page | 31 Do all backward compatible fixes look ugly because we are not allowed to make refactoring?
  • 32. © 2016 Magento, Inc. Page | 32 Coupling Between Objects Reaches Its Limit with a New Dependency
  • 33. © 2016 Magento, Inc. Page | 33 We MUST do continuous Refactoring! Backward Compatibility should not be an excuse for not doing refactoring!
  • 34. © 2016 Magento, Inc. Page | 34 This is how Backward Compatible fix should look like
  • 35. © 2016 Magento, Inc. Page | 35 Q & A @iminyaylo

Editor's Notes

  • #9: Backward compatibility is a property of a system, product, or technology that allows for interoperability with an older legacy system
  • #15: We promise to be backward compatible for classes and methods annotated with @api within MINOR and PATCH updates to our components. As changes are introduced, we annotate methods with @deprecated. The methods are removed only with the next MAJOR component version. 
  • #18: Let’s recap what we had with Magento 1 – where everything is an extension points. All the protected mess and so on. We can’t make changes in contract – all changes suppose to extend existing contract.
  • #22: Tilde = Significant Release Operator