SlideShare a Scribd company logo
© 2016 Magento, Inc. Page | 1
API Design
Best practices
Igor Miniailo
Magento 2 Architect
© 2016 Magento, Inc. Page | 2
© 2016 Magento, Inc. Page | 3
© 2016 Magento, Inc. Page | 4
Why is API so crucial?
© 2016 Magento, Inc. Page | 5
© 2016 Magento, Inc. Page | 6
© 2016 Magento, Inc. Page | 7
© 2016 Magento, Inc. Page | 8
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 | 9
The backward compatibility policy
applies to PHP code annotated with
@api
© 2016 Magento, Inc. Page | 10
Public and Private code
© 2016 Magento, Inc. Page | 11
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 | 12
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 | 13
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. is a set of interfaces and their
implementations that a module provides to other
modules
• As a Service Provider Interface (SPI). is a set of
interfaces that a module uses internally and allows their
implementation by other modules.
• As both. APIs and SPIs are not mutually exclusive.
© 2016 Magento, Inc. Page | 14
After the code is released, both API and SPI can
be evolved in a backwards-compatible way. But
both have their specific limitations.
© 2016 Magento, Inc. Page | 15
© 2016 Magento, Inc. Page | 16
© 2016 Magento, Inc. Page | 17
© 2016 Magento, Inc. Page | 18
© 2016 Magento, Inc. Page | 19
© 2016 Magento, Inc. Page | 20
We do not distinguish them separately.
SPIs are annotated the same as APIs.
© 2016 Magento, Inc. Page | 21
Who decides whether interface/class belong to API or SPI?
YOU
© 2016 Magento, Inc. Page | 22
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 | 23
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 | 24
http://devdocs.magento.com/guides/v2.1/release-notes/backward-
incompatible-changes-2.1.html
© 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
MagentoCatalogApiCategoryRepositoryInterface
© 2016 Magento, Inc. Page | 28
MagentoCatalogApiCategoryListInterface
© 2016 Magento, Inc. Page | 29
PHP - Prohibited Code Changes
• Static function removal
• Parameter addition in public methods
• Parameter addition in protected
methods
© 2016 Magento, Inc. Page | 30
© 2016 Magento, Inc. Page | 31
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 | 32
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 | 33
PHP - Prohibited Code Changes
• Modifying the default values of
optional arguments in public and
protected methods
• Removing or renaming constants
© 2016 Magento, Inc. Page | 34
The main rule is that backwards compatibility
is more important than niceness and effort of
the implementation.
© 2016 Magento, Inc. Page | 35
Coupling Between Objects Reaches Its Limit with
a New Dependency
© 2016 Magento, Inc. Page | 36
We MUST do continuous Refactoring!
Backward Compatibility should not be an excuse
for not doing refactoring!
© 2016 Magento, Inc. Page | 37
Backward Compatible Fix
*it works (most of the time), but code quality
is far from good enough
© 2016 Magento, Inc. Page | 38
Good object oriented programming in the service layer is basically
functional programming:
• constructor injection
• immutable state
• single responsibility principle
• uniform interfaces
• value objects passed across services
Bringing these concepts to an extreme leads to single-method,
immutable objects.
© 2016 Magento, Inc. Page | 39
© 2016 Magento, Inc. Page | 40
Why execute but not __invoke?
© 2016 Magento, Inc. Page | 41
PHP 7
• Return Types
• Scalar Type hinting
© 2016 Magento, Inc. Page | 42
Repositories
In Magento 2 Repositories are considered as an implementation
of Facade pattern which provides a simplified interface to a larger body
of code responsible for Domain Entity management.
The main intention is to make API more readable and reduce
dependencies of business logic code on the inner workings of a
module, since most code uses the facade, thus allowing more flexibility
in developing the system.
© 2016 Magento, Inc. Page | 43
Repositories
© 2016 Magento, Inc. Page | 44
© 2016 Magento, Inc. Page | 45
© 2016 Magento, Inc. Page | 46
Good API design
Don't make your client do anything you can do
for them (this reduces the amount of boilerplate
code your client will have)
© 2016 Magento, Inc. Page | 47
© 2016 Magento, Inc. Page | 48
Q & A
@iminyaylo
engcom@magent.com

More Related Content

What's hot

Explaining API Integration: How Does API Integration work?
Explaining API Integration: How Does API Integration work?Explaining API Integration: How Does API Integration work?
Explaining API Integration: How Does API Integration work?
DavidAltmen
 
What do you mean by "API as a Product"?
What do you mean by "API as a Product"?What do you mean by "API as a Product"?
What do you mean by "API as a Product"?
Lou Powell
 
APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...
APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...
APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...
apidays
 
apidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVA
apidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVAapidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVA
apidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVA
apidays
 
apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...
apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...
apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...
apidays
 
apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...
apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...
apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...
apidays
 
apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...
apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...
apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...
apidays
 
apidays LIVE Paris - Marketplace API modernization: how to scale your busines...
apidays LIVE Paris - Marketplace API modernization: how to scale your busines...apidays LIVE Paris - Marketplace API modernization: how to scale your busines...
apidays LIVE Paris - Marketplace API modernization: how to scale your busines...
apidays
 
APIs for... Your Mom
APIs for... Your MomAPIs for... Your Mom
APIs for... Your Mom
Carlo Longino
 
Mapping out your API Strategy - 4.20.11 Webinar slides
Mapping out your API Strategy - 4.20.11 Webinar slidesMapping out your API Strategy - 4.20.11 Webinar slides
Mapping out your API Strategy - 4.20.11 Webinar slides
Apigee | Google Cloud
 
API Strategy Introduction
API Strategy IntroductionAPI Strategy Introduction
API Strategy Introduction
Doug Gregory
 
APIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPI
APIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPIAPIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPI
APIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPI
apidays
 
How APIs Transform Both Your Business and Technology
How APIs Transform Both Your Business and TechnologyHow APIs Transform Both Your Business and Technology
How APIs Transform Both Your Business and Technology
WSO2
 
APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...
APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...
APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...
apidays
 
apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...
apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...
apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...
apidays
 
Vizag Virtual Meetup #7: Trending API Topics for 2022
Vizag Virtual Meetup #7: Trending API Topics for 2022Vizag Virtual Meetup #7: Trending API Topics for 2022
Vizag Virtual Meetup #7: Trending API Topics for 2022
Ravi Tamada
 
APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...
APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...
APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...
apidays
 
APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...
APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...
APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...
apidays
 
[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking
[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking
[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking
WSO2
 
apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...
apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...
apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...
apidays
 

What's hot (20)

Explaining API Integration: How Does API Integration work?
Explaining API Integration: How Does API Integration work?Explaining API Integration: How Does API Integration work?
Explaining API Integration: How Does API Integration work?
 
What do you mean by "API as a Product"?
What do you mean by "API as a Product"?What do you mean by "API as a Product"?
What do you mean by "API as a Product"?
 
APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...
APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...
APIdays Paris 2019 - Zero Downtime in API Management by Waldemar Rosenfeld, A...
 
apidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVA
apidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVAapidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVA
apidays LIVE London 2021 - Banking APIs Evolution by Hector Arias, BBVA
 
apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...
apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...
apidays LIVE Paris 2021 - 5 Learnings Shaping Our View on the Future of APIs ...
 
apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...
apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...
apidays LIVE Singapore 2021 - What financial services can learn from Marketpl...
 
apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...
apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...
apidays LIVE Australia 2021 - Composing a Headless and Composable Commerce Ar...
 
apidays LIVE Paris - Marketplace API modernization: how to scale your busines...
apidays LIVE Paris - Marketplace API modernization: how to scale your busines...apidays LIVE Paris - Marketplace API modernization: how to scale your busines...
apidays LIVE Paris - Marketplace API modernization: how to scale your busines...
 
APIs for... Your Mom
APIs for... Your MomAPIs for... Your Mom
APIs for... Your Mom
 
Mapping out your API Strategy - 4.20.11 Webinar slides
Mapping out your API Strategy - 4.20.11 Webinar slidesMapping out your API Strategy - 4.20.11 Webinar slides
Mapping out your API Strategy - 4.20.11 Webinar slides
 
API Strategy Introduction
API Strategy IntroductionAPI Strategy Introduction
API Strategy Introduction
 
APIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPI
APIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPIAPIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPI
APIdays Zurich 2019 - The Three Pillars of API Strategy Erik Wilde, GoodAPI
 
How APIs Transform Both Your Business and Technology
How APIs Transform Both Your Business and TechnologyHow APIs Transform Both Your Business and Technology
How APIs Transform Both Your Business and Technology
 
APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...
APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...
APIdays Zurich 2019 - Boosting the Digital Transformation at UBS with APIs Ro...
 
apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...
apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...
apidays LIVE Helsinki & North - Bye bye to the insurance monolith - case Eule...
 
Vizag Virtual Meetup #7: Trending API Topics for 2022
Vizag Virtual Meetup #7: Trending API Topics for 2022Vizag Virtual Meetup #7: Trending API Topics for 2022
Vizag Virtual Meetup #7: Trending API Topics for 2022
 
APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...
APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...
APIdays Zurich 2019 - Digital Ecosystems, fueled by APIs Matthias Biehl, API ...
 
APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...
APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...
APIdays Zurich 2019 - The experience of BBVA API Market David Ramos Lehnhoff,...
 
[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking
[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking
[WSO2 Summit EMEA 2020] Experiencing the Benefits of API Driven Open Banking
 
apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...
apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...
apidays LIVE London 2021 - Presenting the Kubernetes Browser by Daria Muehlet...
 

Similar to API design best practices

Backward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide WebinarBackward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide Webinar
Igor Miniailo
 
Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NL
Igor Miniailo
 
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
Igor Miniailo
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2
Igor Miniailo
 
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
Magecom UK Limited
 
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
Atwix
 
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.
Elogic Magento Development
 
MageConf 2017, Design API Best Practices
MageConf 2017, Design API Best PracticesMageConf 2017, Design API Best Practices
MageConf 2017, Design API Best Practices
Igor Miniailo
 
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
Meet Magento Italy
 
Testing in Magento 2
Testing in Magento 2 Testing in Magento 2
Testing in Magento 2
Igor Miniailo
 
Volodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design PlatformVolodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design Platform
Meet Magento Italy
 
Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
Meet Magento Italy
 
Magento2.3 API Functional Testing
Magento2.3 API Functional TestingMagento2.3 API Functional Testing
Magento2.3 API Functional Testing
Vishwas Bhatnagar
 
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
Igor Miniailo
 
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
Tom Erskine
 
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.
Elogic Magento Development
 
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Meet Magento Italy
 
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
Igor Miniailo
 
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
atishgoswami
 
Mage Titans USA 2016 - Eugene Tulika - Integrations with Magento, end to end...
Mage Titans USA 2016 - Eugene Tulika -  Integrations with Magento, end to end...Mage Titans USA 2016 - Eugene Tulika -  Integrations with Magento, end to end...
Mage Titans USA 2016 - Eugene Tulika - Integrations with Magento, end to end...
Stacey Whitney
 

Similar to API design best practices (20)

Backward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide WebinarBackward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide Webinar
 
Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NL
 
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
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2
 
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
 
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
 
Testing in Magento 2
Testing in Magento 2 Testing in Magento 2
Testing in Magento 2
 
Volodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design PlatformVolodymyr Kublytskyi - Develop Product, Design Platform
Volodymyr Kublytskyi - Develop Product, Design Platform
 
Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
 
Magento2.3 API Functional Testing
Magento2.3 API Functional TestingMagento2.3 API Functional Testing
Magento2.3 API Functional Testing
 
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
 
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
 
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.
 
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
Max Pronko - 10 migration mistakes from Magento 1 to Magento 2
 
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
 
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
 
Mage Titans USA 2016 - Eugene Tulika - Integrations with Magento, end to end...
Mage Titans USA 2016 - Eugene Tulika -  Integrations with Magento, end to end...Mage Titans USA 2016 - Eugene Tulika -  Integrations with Magento, end to end...
Mage Titans USA 2016 - Eugene Tulika - Integrations with Magento, end to end...
 

More from Igor Miniailo

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
Igor Miniailo
 
Magento Storefront architecture
Magento Storefront architectureMagento Storefront architecture
Magento Storefront architecture
Igor Miniailo
 
Something Architecture
Something ArchitectureSomething Architecture
Something Architecture
Igor Miniailo
 
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
Igor Miniailo
 
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
Igor Miniailo
 
Magento Multi-Source Inventory (MSI)
Magento Multi-Source Inventory (MSI)Magento Multi-Source Inventory (MSI)
Magento Multi-Source Inventory (MSI)
Igor Miniailo
 
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)
Igor Miniailo
 
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
Igor Miniailo
 
Dare to Share Magento Community Engineering
Dare to Share Magento Community Engineering Dare to Share Magento Community Engineering
Dare to Share Magento Community Engineering
Igor Miniailo
 
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
Igor Miniailo
 
Magento Developer Talk. Microservice Architecture and Actor Model
Magento Developer Talk. Microservice Architecture and Actor ModelMagento Developer Talk. Microservice Architecture and Actor Model
Magento Developer Talk. Microservice Architecture and Actor Model
Igor Miniailo
 
Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2 Applying Code Customizations to Magento 2
Applying Code Customizations to Magento 2
Igor Miniailo
 
Modular development in Magento 2
Modular development in Magento 2Modular development in Magento 2
Modular development in Magento 2
Igor Miniailo
 
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Igor Miniailo
 
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от КотлетСommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Igor Miniailo
 

More from Igor Miniailo (15)

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
 
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)
 
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
 
Magento Developer Talk. Microservice Architecture and Actor Model
Magento Developer Talk. Microservice Architecture and Actor ModelMagento Developer Talk. Microservice Architecture and Actor Model
Magento Developer Talk. Microservice Architecture and Actor Model
 
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
 
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
Мониторинг веб приложений на PHP в режиме реального времени с помощью Pinba. ...
 
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от КотлетСommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
Сommand Query Responsibility Segregation (CQRS) - Отделяем Мух от Котлет
 

Recently uploaded

Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 

Recently uploaded (20)

Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 

API design best practices

  • 1. © 2016 Magento, Inc. Page | 1 API Design Best practices Igor Miniailo Magento 2 Architect
  • 2. © 2016 Magento, Inc. Page | 2
  • 3. © 2016 Magento, Inc. Page | 3
  • 4. © 2016 Magento, Inc. Page | 4 Why is API so crucial?
  • 5. © 2016 Magento, Inc. Page | 5
  • 6. © 2016 Magento, Inc. Page | 6
  • 7. © 2016 Magento, Inc. Page | 7
  • 8. © 2016 Magento, Inc. Page | 8 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
  • 9. © 2016 Magento, Inc. Page | 9 The backward compatibility policy applies to PHP code annotated with @api
  • 10. © 2016 Magento, Inc. Page | 10 Public and Private code
  • 11. © 2016 Magento, Inc. Page | 11 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.
  • 12. © 2016 Magento, Inc. Page | 12 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
  • 13. © 2016 Magento, Inc. Page | 13 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. is a set of interfaces and their implementations that a module provides to other modules • As a Service Provider Interface (SPI). is a set of interfaces that a module uses internally and allows their implementation by other modules. • As both. APIs and SPIs are not mutually exclusive.
  • 14. © 2016 Magento, Inc. Page | 14 After the code is released, both API and SPI can be evolved in a backwards-compatible way. But both have their specific limitations.
  • 15. © 2016 Magento, Inc. Page | 15
  • 16. © 2016 Magento, Inc. Page | 16
  • 17. © 2016 Magento, Inc. Page | 17
  • 18. © 2016 Magento, Inc. Page | 18
  • 19. © 2016 Magento, Inc. Page | 19
  • 20. © 2016 Magento, Inc. Page | 20 We do not distinguish them separately. SPIs are annotated the same as APIs.
  • 21. © 2016 Magento, Inc. Page | 21 Who decides whether interface/class belong to API or SPI? YOU
  • 22. © 2016 Magento, Inc. Page | 22 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) }, ... }
  • 23. © 2016 Magento, Inc. Page | 23 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) }, ... }
  • 24. © 2016 Magento, Inc. Page | 24 http://devdocs.magento.com/guides/v2.1/release-notes/backward- incompatible-changes-2.1.html
  • 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 MagentoCatalogApiCategoryRepositoryInterface
  • 28. © 2016 Magento, Inc. Page | 28 MagentoCatalogApiCategoryListInterface
  • 29. © 2016 Magento, Inc. Page | 29 PHP - Prohibited Code Changes • Static function removal • Parameter addition in public methods • Parameter addition in protected methods
  • 30. © 2016 Magento, Inc. Page | 30
  • 31. © 2016 Magento, Inc. Page | 31 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
  • 32. © 2016 Magento, Inc. Page | 32 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 ... } }
  • 33. © 2016 Magento, Inc. Page | 33 PHP - Prohibited Code Changes • Modifying the default values of optional arguments in public and protected methods • Removing or renaming constants
  • 34. © 2016 Magento, Inc. Page | 34 The main rule is that backwards compatibility is more important than niceness and effort of the implementation.
  • 35. © 2016 Magento, Inc. Page | 35 Coupling Between Objects Reaches Its Limit with a New Dependency
  • 36. © 2016 Magento, Inc. Page | 36 We MUST do continuous Refactoring! Backward Compatibility should not be an excuse for not doing refactoring!
  • 37. © 2016 Magento, Inc. Page | 37 Backward Compatible Fix *it works (most of the time), but code quality is far from good enough
  • 38. © 2016 Magento, Inc. Page | 38 Good object oriented programming in the service layer is basically functional programming: • constructor injection • immutable state • single responsibility principle • uniform interfaces • value objects passed across services Bringing these concepts to an extreme leads to single-method, immutable objects.
  • 39. © 2016 Magento, Inc. Page | 39
  • 40. © 2016 Magento, Inc. Page | 40 Why execute but not __invoke?
  • 41. © 2016 Magento, Inc. Page | 41 PHP 7 • Return Types • Scalar Type hinting
  • 42. © 2016 Magento, Inc. Page | 42 Repositories In Magento 2 Repositories are considered as an implementation of Facade pattern which provides a simplified interface to a larger body of code responsible for Domain Entity management. The main intention is to make API more readable and reduce dependencies of business logic code on the inner workings of a module, since most code uses the facade, thus allowing more flexibility in developing the system.
  • 43. © 2016 Magento, Inc. Page | 43 Repositories
  • 44. © 2016 Magento, Inc. Page | 44
  • 45. © 2016 Magento, Inc. Page | 45
  • 46. © 2016 Magento, Inc. Page | 46 Good API design Don't make your client do anything you can do for them (this reduces the amount of boilerplate code your client will have)
  • 47. © 2016 Magento, Inc. Page | 47
  • 48. © 2016 Magento, Inc. Page | 48 Q & A @iminyaylo engcom@magent.com

Editor's Notes

  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