SlideShare ist ein Scribd-Unternehmen logo
1 von 31
© 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
Backward Compatibility
Backward compatibility is a property of a system,
product, or technology that allows for interoperability
with an older legacy system (c) - Wiki
© 2016 Magento, Inc. Page | 4
Why does BC matter?
Merchants and developers want the process of upgrading
between revisions of Magento 2 to be as easy as possible.
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 | 5
Does Magento have a lot of bugs?
Are these bugs annoying for Magento
developers?
© 2016 Magento, Inc. Page | 6
Keep Magento backwards compatible vs.
fixing its flaws?
© 2016 Magento, Inc. Page | 7
We MUST do BOTH
© 2016 Magento, Inc. Page | 8
Backward Compatible Fix
*it works (most of the time), but code quality
is far from good enough
© 2016 Magento, Inc. Page | 9
Backward compatibility (BC)
policy for Magento code
© 2016 Magento, Inc. Page | 10
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
The backward compatibility policy applies to PHP code
annotated with @api
© 2016 Magento, Inc. Page | 11
Public and Private code
© 2016 Magento, Inc. Page | 12
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 | 13
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 | 14
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. For example, in a service contract, we expect all calls to a
module to be done through the Interface (API), but we also have
support for third parties to provide alternate implementations (SPI).
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 | 15
Who decides whether interface/class belong to API or SPI?
YOU
© 2016 Magento, Inc. Page | 16
Dependency Rules API
If a module uses (calls) an API, it should be dependent on the MAJOR
version and the system provides backward compatibility in scope of
current major version.
API dependency example
{
...
"require": {
"magento/module-customer": "~100.0", // (>=100.0 <101.0.0)
},
...
}
© 2016 Magento, Inc. Page | 17
Dependency Rules SPI
If a module implements an API/SPI, it should be dependent on the
MAJOR+MINOR version, and the system provides backward
compatibility in scope of the current minor version.
SPI dependency example
{
...
"require": {
"magento/module-customer": "~100.0.0", // (>=100.0.0 <100.1.0)
},
...
}
© 2016 Magento, Inc. Page | 18
http://devdocs.magento.com/guides/v2.1/release-notes/backward-
incompatible-changes-2.1.html
© 2016 Magento, Inc. Page | 19
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 | 20
Prohibited Code Changes
© 2016 Magento, Inc. Page | 21
• Interface/class removal
Mark with @deprecated tag instead of removing it. Mark also all its methods
as deprecated, so IDE highlights them as deprecated.
• Public & protected method removal
Mark with @deprecated tag instead.
Continue returning the same results from the method if possible, so the old
functionality is preserved.
• Introduction of a method to a class or interface
Create a new interface with a new method.
New interface may take over some existing methods from the class if it makes sense to group them
together. In this case, corresponding methods in the old interface/class must be deprecated with
@see annotation referencing the new interface/method. The old methods should proxy the calls to
the new interface instead of duplicating the logic.
PHP
© 2016 Magento, Inc. Page | 22
PHP
• static function removal
• parameter addition in public methods
Add a new method with necessary parameters to new interface.
Deprecate old method. Reference the new method in a @see tag as a
recommended replacement. Include an explanation of why the old
method was replaced with the new one (e.g., there is a bug in the old
method).
• parameter addition in protected methods
Preserve the method as is. Create a new method with the new
signature, and deprecate the old method. If possible declare the new
method as private.
© 2016 Magento, Inc. Page | 23
PHP
• method argument type modification
• modification of types of thrown exceptions (unless a new
exception is a subtype of the old one)
• constructor modification
Add the new optional parameter to the constructor at the end of
arguments list.
In the constructor body, if new dependency is not provided (value of
introduced argument is null) fetch the dependency using
MagentoFrameworkAppObjectionManager::getInstance().
© 2016 Magento, Inc. Page | 24
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 | 25
The main rule is that backwards compatibility
is more important than niceness and effort of
the implementation.
© 2016 Magento, Inc. Page | 26
Do all backward
compatible fixes look
ugly because we are not
allowed to make
refactoring?
© 2016 Magento, Inc. Page | 27
Coupling Between Objects Reaches Its Limit with
a New Dependency
© 2016 Magento, Inc. Page | 28
Coupling Between Objects - Refactoring
• For preserving backwards compatibility, public and protected
interface of the class must be preserved. But the class
should be reviewed and refactored so that parts of the logic
go into smaller specialized classes.
• The existing class then should be functioning as a facade to
preserve backwards compatibility, so existing usages of the
refactored methods were not broken
• The old public/protected methods should be marked as
deprecated with @see tag suggesting the new
implementation for new usages
• All unused private properties/methods can be removed now
© 2016 Magento, Inc. Page | 29
Coupling Between Objects - Refactoring
• All unused protected properties must be marked as
deprecated.
• Type of the variable can be removed from the DocBlock, so
it's not calculated as one of the dependencies
To preserve constructor signature:
• Remove type hinting for unused parameters. This will remove
dependency on their type
• Add @SuppressWarnings(PHPMD.UnusedFormalParameter)
for unused parameters
© 2016 Magento, Inc. Page | 30
This is how Backward
Compatible fix should
look like
© 2016 Magento, Inc. Page | 31
Q & A
@iminyaylo

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Logging best practice in mule using logger component
Logging best practice in mule using logger componentLogging best practice in mule using logger component
Logging best practice in mule using logger component
 
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.ioMuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
 
MuleSoft certified platform architect-level 1 Real Exam Questions
MuleSoft certified platform architect-level 1 Real Exam QuestionsMuleSoft certified platform architect-level 1 Real Exam Questions
MuleSoft certified platform architect-level 1 Real Exam Questions
 
MuleSoft Surat Virtual Meetup#8 - Anypoint Business Group Connected Apps and ...
MuleSoft Surat Virtual Meetup#8 - Anypoint Business Group Connected Apps and ...MuleSoft Surat Virtual Meetup#8 - Anypoint Business Group Connected Apps and ...
MuleSoft Surat Virtual Meetup#8 - Anypoint Business Group Connected Apps and ...
 
Telling the world why we love mule soft!
Telling the world why we love mule soft!Telling the world why we love mule soft!
Telling the world why we love mule soft!
 
Mule testing
Mule testingMule testing
Mule testing
 
MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...
MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...
MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...
 
MuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLB
MuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLBMuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLB
MuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLB
 
Mule esb–api layer
Mule esb–api layerMule esb–api layer
Mule esb–api layer
 
Mule sap connector
Mule sap connectorMule sap connector
Mule sap connector
 
Exposing Web Service (CXF) With Mule ESB
Exposing Web Service (CXF) With Mule ESBExposing Web Service (CXF) With Mule ESB
Exposing Web Service (CXF) With Mule ESB
 
Indianapolis mulesoft meetup_sep_11_2021
Indianapolis mulesoft meetup_sep_11_2021Indianapolis mulesoft meetup_sep_11_2021
Indianapolis mulesoft meetup_sep_11_2021
 
Miracle mulesoft tech_cloud_hub
Miracle mulesoft tech_cloud_hubMiracle mulesoft tech_cloud_hub
Miracle mulesoft tech_cloud_hub
 
Nashik MuleSoft Virtual Meetup#1 - Shared and Dedicated Load Balancer
Nashik MuleSoft Virtual Meetup#1 - Shared and Dedicated Load BalancerNashik MuleSoft Virtual Meetup#1 - Shared and Dedicated Load Balancer
Nashik MuleSoft Virtual Meetup#1 - Shared and Dedicated Load Balancer
 
Best practices for multi saa s integrations
Best practices for multi saa s integrationsBest practices for multi saa s integrations
Best practices for multi saa s integrations
 
Anypoint platform
Anypoint platformAnypoint platform
Anypoint platform
 
MuleSoft Surat Virtual Meetup#24 - MuleSoft and Salesforce Integration and De...
MuleSoft Surat Virtual Meetup#24 - MuleSoft and Salesforce Integration and De...MuleSoft Surat Virtual Meetup#24 - MuleSoft and Salesforce Integration and De...
MuleSoft Surat Virtual Meetup#24 - MuleSoft and Salesforce Integration and De...
 
MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...
MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...
MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...
 
The anypoint platform for API's
The anypoint platform for API'sThe anypoint platform for API's
The anypoint platform for API's
 
Anypoint Platform Deployment Strategies
Anypoint Platform Deployment StrategiesAnypoint Platform Deployment Strategies
Anypoint Platform Deployment Strategies
 

Andere mochten auch

Johnson & Johnson Scholarship for BDPA Students
Johnson & Johnson Scholarship for BDPA StudentsJohnson & Johnson Scholarship for BDPA Students
Johnson & Johnson Scholarship for BDPA Students
BDPA Education and Technology Foundation
 

Andere mochten auch (13)

Secure development environment @ Meet Magento Croatia 2017
Secure development environment @ Meet Magento Croatia 2017Secure development environment @ Meet Magento Croatia 2017
Secure development environment @ Meet Magento Croatia 2017
 
#lavitrinadeltesoro : joyas bibliográficas de @la_UPM / @biblioUPM - 2017
#lavitrinadeltesoro : joyas bibliográficas de @la_UPM / @biblioUPM - 2017#lavitrinadeltesoro : joyas bibliográficas de @la_UPM / @biblioUPM - 2017
#lavitrinadeltesoro : joyas bibliográficas de @la_UPM / @biblioUPM - 2017
 
14 Banking Facts to Help You Master the New Digital Economy
14 Banking Facts to Help You Master the New Digital Economy14 Banking Facts to Help You Master the New Digital Economy
14 Banking Facts to Help You Master the New Digital Economy
 
Johnson & Johnson Scholarship for BDPA Students
Johnson & Johnson Scholarship for BDPA StudentsJohnson & Johnson Scholarship for BDPA Students
Johnson & Johnson Scholarship for BDPA Students
 
Investment Opportunities in Vietnam
Investment Opportunities in VietnamInvestment Opportunities in Vietnam
Investment Opportunities in Vietnam
 
The social care common inspection framework (SCCIF): an introduction
The social care common inspection framework (SCCIF): an introductionThe social care common inspection framework (SCCIF): an introduction
The social care common inspection framework (SCCIF): an introduction
 
Diagnóstico SEO Técnico con Herramientas #TheInbounder
Diagnóstico SEO Técnico con Herramientas #TheInbounderDiagnóstico SEO Técnico con Herramientas #TheInbounder
Diagnóstico SEO Técnico con Herramientas #TheInbounder
 
Global Education and Skills Forum 2017 - Educating Global Citizens
Global Education and Skills Forum  2017 -  Educating Global CitizensGlobal Education and Skills Forum  2017 -  Educating Global Citizens
Global Education and Skills Forum 2017 - Educating Global Citizens
 
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
 
[Memoire 2016] Comment les entreprises peuvent-elles améliorer leur e-réputat...
[Memoire 2016] Comment les entreprises peuvent-elles améliorer leur e-réputat...[Memoire 2016] Comment les entreprises peuvent-elles améliorer leur e-réputat...
[Memoire 2016] Comment les entreprises peuvent-elles améliorer leur e-réputat...
 
Horarios de #BibliotecaAbierta y #HorarioAmpliado 2017 / Biblioteca UPM
Horarios de #BibliotecaAbierta y #HorarioAmpliado 2017 / Biblioteca UPMHorarios de #BibliotecaAbierta y #HorarioAmpliado 2017 / Biblioteca UPM
Horarios de #BibliotecaAbierta y #HorarioAmpliado 2017 / Biblioteca UPM
 
10 Must-Know Commercial Real Estate Terms
10 Must-Know Commercial Real Estate Terms10 Must-Know Commercial Real Estate Terms
10 Must-Know Commercial Real Estate Terms
 
How to Create a Growth Framework
How to Create a Growth FrameworkHow to Create a Growth Framework
How to Create a Growth Framework
 

Ähnlich wie Backward Compatibility Developer's Guide in Magento 2

Ähnlich wie Backward Compatibility Developer's Guide in Magento 2 (20)

Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NL
 
Backward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide WebinarBackward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide Webinar
 
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZBackward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
 
API design best practices
API design best practicesAPI design best practices
API design best practices
 
API Design Best Practices by Igor Miniailo
API Design Best Practices by Igor MiniailoAPI Design Best Practices by Igor Miniailo
API Design Best Practices by Igor Miniailo
 
Igor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best PracticesIgor Miniailo - Magento 2 API Design Best Practices
Igor Miniailo - Magento 2 API Design Best Practices
 
Chernivtsi Magento Meetup&Contribution day. Miniailo.I.
Chernivtsi Magento Meetup&Contribution day. Miniailo.I. Chernivtsi Magento Meetup&Contribution day. Miniailo.I.
Chernivtsi Magento Meetup&Contribution day. Miniailo.I.
 
MageConf 2017, Design API Best Practices
MageConf 2017, Design API Best PracticesMageConf 2017, Design API Best Practices
MageConf 2017, Design API Best Practices
 
Best Practics for Automating Next Generation Firewall Change Processes
Best Practics for Automating Next Generation Firewall Change ProcessesBest Practics for Automating Next Generation Firewall Change Processes
Best Practics for Automating Next Generation Firewall Change Processes
 
Eugene Shakhsuvarov - Improving enterprise store scalability using AMQP and A...
Eugene Shakhsuvarov - Improving enterprise store scalability using AMQP and A...Eugene Shakhsuvarov - Improving enterprise store scalability using AMQP and A...
Eugene Shakhsuvarov - Improving enterprise store scalability using AMQP and A...
 
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum PerformanceEugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
 
Magento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data PatchesMagento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data Patches
 
Magento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and OverviewMagento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and Overview
 
Using Magento 2.3 MySQL Queues
Using Magento 2.3 MySQL QueuesUsing Magento 2.3 MySQL Queues
Using Magento 2.3 MySQL Queues
 
7 network programmability concepts python-ansible
7 network programmability concepts python-ansible7 network programmability concepts python-ansible
7 network programmability concepts python-ansible
 
Oleksii Korshenko - Magento 2 Backwards Compatible Policy
Oleksii Korshenko - Magento 2 Backwards Compatible PolicyOleksii Korshenko - Magento 2 Backwards Compatible Policy
Oleksii Korshenko - Magento 2 Backwards Compatible Policy
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Everything about the magento open source 2
Everything about the magento open source 2Everything about the magento open source 2
Everything about the magento open source 2
 
7 network programmability concepts api
7 network programmability concepts api7 network programmability concepts api
7 network programmability concepts api
 
Chernivtsi Magento Meetup&Contribution day. Naida V.
Chernivtsi Magento Meetup&Contribution day. Naida V.Chernivtsi Magento Meetup&Contribution day. Naida V.
Chernivtsi Magento Meetup&Contribution day. Naida V.
 

Mehr von Igor Miniailo

Mehr von Igor Miniailo (16)

Extensibility of Magento, the look into the future
Extensibility of Magento, the look into the futureExtensibility of Magento, the look into the future
Extensibility of Magento, the look into the future
 
Magento Storefront architecture
Magento Storefront architectureMagento Storefront architecture
Magento Storefront architecture
 
Something Architecture
Something ArchitectureSomething Architecture
Something Architecture
 
A long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NLA long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NL
 
The long way from Monolith to Microservices
The long way from Monolith to MicroservicesThe long way from Monolith to Microservices
The long way from Monolith to Microservices
 
CQRS and Event-Sourcing in Magento2 by examples of MSI
CQRS and Event-Sourcing in Magento2 by examples of MSICQRS and Event-Sourcing in Magento2 by examples of MSI
CQRS and Event-Sourcing in Magento2 by examples of MSI
 
Multi-Source Inventory. Imagine. Las Vegas. 2018
Multi-Source Inventory. Imagine. Las Vegas. 2018Multi-Source Inventory. Imagine. Las Vegas. 2018
Multi-Source Inventory. Imagine. Las Vegas. 2018
 
Magento Multi-Source Inventory (MSI)
Magento Multi-Source Inventory (MSI)Magento Multi-Source Inventory (MSI)
Magento Multi-Source Inventory (MSI)
 
Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
Magento 2 Automated Testing via examples of Multi-Source Inventory (MSI)
 
Testing in Magento 2
Testing in Magento 2 Testing in Magento 2
Testing in Magento 2
 
Architecture and workflow of Multi-Source Inventory
Architecture and workflow of Multi-Source InventoryArchitecture and workflow of Multi-Source Inventory
Architecture and workflow of Multi-Source Inventory
 
Dare to Share Magento Community Engineering
Dare to Share Magento Community Engineering Dare to Share Magento Community Engineering
Dare to Share Magento Community Engineering
 
Multi Source Inventory (MSI) in Magento 2
Multi Source Inventory (MSI) in Magento 2 Multi Source Inventory (MSI) in Magento 2
Multi Source Inventory (MSI) in Magento 2
 
Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2 Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2
 
Modular development in Magento 2
Modular development in Magento 2Modular development in Magento 2
Modular development in Magento 2
 
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от КотлетСommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
 

Kürzlich hochgeladen

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Kürzlich hochgeladen (20)

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
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...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

Backward Compatibility Developer's Guide in Magento 2

  • 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 Backward Compatibility Backward compatibility is a property of a system, product, or technology that allows for interoperability with an older legacy system (c) - Wiki
  • 4. © 2016 Magento, Inc. Page | 4 Why does BC matter? Merchants and developers want the process of upgrading between revisions of Magento 2 to be as easy as possible. For merchants, the process must be cost-effective, while developers want their extensions to be forward- compatible for as long as possible.
  • 5. © 2016 Magento, Inc. Page | 5 Does Magento have a lot of bugs? Are these bugs annoying for Magento developers?
  • 6. © 2016 Magento, Inc. Page | 6 Keep Magento backwards compatible vs. fixing its flaws?
  • 7. © 2016 Magento, Inc. Page | 7 We MUST do BOTH
  • 8. © 2016 Magento, Inc. Page | 8 Backward Compatible Fix *it works (most of the time), but code quality is far from good enough
  • 9. © 2016 Magento, Inc. Page | 9 Backward compatibility (BC) policy for Magento code
  • 10. © 2016 Magento, Inc. Page | 10 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 The backward compatibility policy applies to PHP code annotated with @api
  • 11. © 2016 Magento, Inc. Page | 11 Public and Private code
  • 12. © 2016 Magento, Inc. Page | 12 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.
  • 13. © 2016 Magento, Inc. Page | 13 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
  • 14. © 2016 Magento, Inc. Page | 14 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. For example, in a service contract, we expect all calls to a module to be done through the Interface (API), but we also have support for third parties to provide alternate implementations (SPI). APIs and SPIs are not mutually exclusive. Therefore, we do not distinguish them separately. SPIs are annotated the same as APIs.
  • 15. © 2016 Magento, Inc. Page | 15 Who decides whether interface/class belong to API or SPI? YOU
  • 16. © 2016 Magento, Inc. Page | 16 Dependency Rules API If a module uses (calls) an API, it should be dependent on the MAJOR version and the system provides backward compatibility in scope of current major version. API dependency example { ... "require": { "magento/module-customer": "~100.0", // (>=100.0 <101.0.0) }, ... }
  • 17. © 2016 Magento, Inc. Page | 17 Dependency Rules SPI If a module implements an API/SPI, it should be dependent on the MAJOR+MINOR version, and the system provides backward compatibility in scope of the current minor version. SPI dependency example { ... "require": { "magento/module-customer": "~100.0.0", // (>=100.0.0 <100.1.0) }, ... }
  • 18. © 2016 Magento, Inc. Page | 18 http://devdocs.magento.com/guides/v2.1/release-notes/backward- incompatible-changes-2.1.html
  • 19. © 2016 Magento, Inc. Page | 19 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.
  • 20. © 2016 Magento, Inc. Page | 20 Prohibited Code Changes
  • 21. © 2016 Magento, Inc. Page | 21 • Interface/class removal Mark with @deprecated tag instead of removing it. Mark also all its methods as deprecated, so IDE highlights them as deprecated. • Public & protected method removal Mark with @deprecated tag instead. Continue returning the same results from the method if possible, so the old functionality is preserved. • Introduction of a method to a class or interface Create a new interface with a new method. New interface may take over some existing methods from the class if it makes sense to group them together. In this case, corresponding methods in the old interface/class must be deprecated with @see annotation referencing the new interface/method. The old methods should proxy the calls to the new interface instead of duplicating the logic. PHP
  • 22. © 2016 Magento, Inc. Page | 22 PHP • static function removal • parameter addition in public methods Add a new method with necessary parameters to new interface. Deprecate old method. Reference the new method in a @see tag as a recommended replacement. Include an explanation of why the old method was replaced with the new one (e.g., there is a bug in the old method). • parameter addition in protected methods Preserve the method as is. Create a new method with the new signature, and deprecate the old method. If possible declare the new method as private.
  • 23. © 2016 Magento, Inc. Page | 23 PHP • method argument type modification • modification of types of thrown exceptions (unless a new exception is a subtype of the old one) • constructor modification Add the new optional parameter to the constructor at the end of arguments list. In the constructor body, if new dependency is not provided (value of introduced argument is null) fetch the dependency using MagentoFrameworkAppObjectionManager::getInstance().
  • 24. © 2016 Magento, Inc. Page | 24 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 ... } }
  • 25. © 2016 Magento, Inc. Page | 25 The main rule is that backwards compatibility is more important than niceness and effort of the implementation.
  • 26. © 2016 Magento, Inc. Page | 26 Do all backward compatible fixes look ugly because we are not allowed to make refactoring?
  • 27. © 2016 Magento, Inc. Page | 27 Coupling Between Objects Reaches Its Limit with a New Dependency
  • 28. © 2016 Magento, Inc. Page | 28 Coupling Between Objects - Refactoring • For preserving backwards compatibility, public and protected interface of the class must be preserved. But the class should be reviewed and refactored so that parts of the logic go into smaller specialized classes. • The existing class then should be functioning as a facade to preserve backwards compatibility, so existing usages of the refactored methods were not broken • The old public/protected methods should be marked as deprecated with @see tag suggesting the new implementation for new usages • All unused private properties/methods can be removed now
  • 29. © 2016 Magento, Inc. Page | 29 Coupling Between Objects - Refactoring • All unused protected properties must be marked as deprecated. • Type of the variable can be removed from the DocBlock, so it's not calculated as one of the dependencies To preserve constructor signature: • Remove type hinting for unused parameters. This will remove dependency on their type • Add @SuppressWarnings(PHPMD.UnusedFormalParameter) for unused parameters
  • 30. © 2016 Magento, Inc. Page | 30 This is how Backward Compatible fix should look like
  • 31. © 2016 Magento, Inc. Page | 31 Q & A @iminyaylo

Hinweis der Redaktion

  1. 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. 
  2. 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.
  3. Tilde = Significant Release Operator