SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Magento 2
The State of Data Persistence
(Being Pragmatic in the Face of Architectural Uncertainty)
@matthewhaworth
A quick about me
Matthew Haworth
Magento Consultant at Warner Music Group
Twitter: @matthewhaworth
LinkedIn: matthewhaworth
@matthewhaworth
My first experience with Magento 2.0
• Stayed in my comfort zone using old ‘Active Record’ façade
$product = $productFactory->create()->load($productId);
$product->setName(‘New Product Name');
$product->save();
• Learned about new ‘Service Contracts’ architecture, but avoided it
• Eventually dug deeper, learned more best practice and want to
evangelise
@matthewhaworth
Magento 1 Architecture Review
• The Active Record pattern implied that a Model was responsible for
persisting data to the database through ->save()
• However, the Model delegated to the Resource Model
• The Resource Model iterated through the database table’s fields and
pulled those keys from the Model to create an insert/update query.
@matthewhaworth
Model
Resource
Model
->save() ->save($this)
Magento 1 Architecture Review
• The Model was responsible for modelling the data.
• The Resource Model was effectively a Data Mapper.
• Any business logic was either in the Model or in a custom
built service class
@matthewhaworth
Magento 2’s New Architecture
• Magento 2 seeks to formalise this structure by introducing ‘Service
Contracts’.
• Service contracts are a set of interfaces defined for data models and
services.
@matthewhaworth
@matthewhaworth
Magento 2’s New Architecture
• Data persistence within service contracts starts with the ’repository’.
• “A Repository mediates between the domain and data mapping
layers, acting like an in-memory domain object collection.” – Martin
Fowler
@matthewhaworth
No more abstract model!
• Domain objects are now completely independent from the database!
@matthewhaworth
Model Abstract
Model
extends
@matthewhaworth
Magento 1
Magento 2
Model Abstract
Model
Resource Model
Abstract
Resource Model
extends extends
delegates database
map and save
Repository Interface
Repository
Implementation
implements
Data Interface
Data Object
Implementation
implements
is passed to
repository for
save
@matthewhaworth
Magento 1
Magento 2
Model Abstract
Model
Resource Model
Abstract
Resource Model
extends extends
delegates database
map and save
Resource Model
Abstract
Resource Model
extends
Repository Interface
Repository
Implementation
implements
Data Interface
Data Object
Implementation
implements
delegates
database map
and save
is passed to
repository for
save
Why move to repositories?
• Separate the representation of data, business logic and data
persistence
• Beneficial for testing by allowing a substitution point for unit tests
• Repository interfaces provides a version-able, single point of
communication for APIs and other modular dependencies
@matthewhaworth
But wait, there’s a problem…
The object passed to the resource must extend the Abstract Model
public function save(MagentoFrameworkModelAbstractModel $object)
@matthewhaworth
Resource ModelRepository InterfaceData Interface
So what are our options?
1. Implement data interface and extend the Abstract Model,
sacrificing our new found independence.
@matthewhaworth
Data Object
Abstract ModelData Interface
implements extends
So what are our options?
2. Implement the data interface and map to the Abstract Model in
the repository before passing to the resource.
@matthewhaworth
Abstract Model
Implementation
Data Object Repository Resource
map
So what are our options?
3. Best of both worlds!
Implement the data interface, the abstract model and map to the
Abstract Model in the repository before passing to the resource.
@matthewhaworth
Model & Data Object Repository Resource
2. Map to data object
Abstract ModelData Interface
implements extends
1. Submit to save
Model & Data Object
So what are our options?
4. Use a different data persistence layer to the Magento DB Resource,
maybe Doctrine?
@matthewhaworth
So what are our options?
4. Use a different data persistence layer to the Magento DB Resource,
maybe Doctrine?
@matthewhaworth
Nah.
For me, the clear winner is approach 3
• Implement the data interface and
extend the abstract model
• Map from the data interface to
the abstract model in the
repository
• Avoids duplicating an extra model
for the sake of pushing to the
resource
@matthewhaworth
Model & Data Object Repository
Resource
2. Map to data object
Abstract Model Data Interface
implementsextends
1. Submit to save
Model & Data Object
@matthewhaworth
by @VinaiKopp
Where can I see good examples?
Magento_Customer was regarded as the best example.
This module maps its data interfaces to a separate Abstract Model
implementation in its repository (approach 2).
Multi Source Inventory (a set of modules) is currently regarded as the
best example to follow.
Data models in this module both implement the data interface and
extend the data model (approach 3) and also make use of CQRS.
(see MagentoInventoryModelStock @ github.com/magento-engcom/msi)
@matthewhaworth
What does the future look like?
• Removing the Abstract Model entirely
• Moving beforeSave(), afterSave(), etc to plugins and events (AOP)
(They’re also making them ‘bulk-first’.)
• Command Query Responsibility Segregation
@matthewhaworth
Thank you to Alan Kent, Anton Kril and Vinai Kopp
@matthewhaworth
Questions?

Contenu connexe

Similaire à The State Of Data Persistence

Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
Design Patterns
Design PatternsDesign Patterns
Design Patternsimedo.de
 
Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Mathew Beane
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts weili_at_slideshare
 
What is struts_en
What is struts_enWhat is struts_en
What is struts_entechbed
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2divzi1913
 
common design patterns summary.pdf
common design patterns summary.pdfcommon design patterns summary.pdf
common design patterns summary.pdfNikolayRaychev2
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083Divyam Pateriya
 
Architecting an ASP.NET MVC Solution
Architecting an ASP.NET MVC SolutionArchitecting an ASP.NET MVC Solution
Architecting an ASP.NET MVC SolutionAndrea Saltarello
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentationOleksii Usyk
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor FrameworkDamien Magoni
 
Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Clarence Ngoh
 
MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2Mathew Beane
 
Reactive data analysis with vert.x
Reactive data analysis with vert.xReactive data analysis with vert.x
Reactive data analysis with vert.xGerald Muecke
 

Similaire à The State Of Data Persistence (20)

Generic Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity FrameworkGeneric Repository Pattern in MVC3 Application with Entity Framework
Generic Repository Pattern in MVC3 Application with Entity Framework
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2
 
CoreData
CoreDataCoreData
CoreData
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
What is struts_en
What is struts_enWhat is struts_en
What is struts_en
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
common design patterns summary.pdf
common design patterns summary.pdfcommon design patterns summary.pdf
common design patterns summary.pdf
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
Architecting an ASP.NET MVC Solution
Architecting an ASP.NET MVC SolutionArchitecting an ASP.NET MVC Solution
Architecting an ASP.NET MVC Solution
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)
 
MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2MidwestPHP - Getting Started with Magento 2
MidwestPHP - Getting Started with Magento 2
 
Reactive data analysis with vert.x
Reactive data analysis with vert.xReactive data analysis with vert.x
Reactive data analysis with vert.x
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
 

Dernier

Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 

Dernier (20)

Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 

The State Of Data Persistence

  • 1. Magento 2 The State of Data Persistence (Being Pragmatic in the Face of Architectural Uncertainty) @matthewhaworth
  • 2. A quick about me Matthew Haworth Magento Consultant at Warner Music Group Twitter: @matthewhaworth LinkedIn: matthewhaworth @matthewhaworth
  • 3. My first experience with Magento 2.0 • Stayed in my comfort zone using old ‘Active Record’ façade $product = $productFactory->create()->load($productId); $product->setName(‘New Product Name'); $product->save(); • Learned about new ‘Service Contracts’ architecture, but avoided it • Eventually dug deeper, learned more best practice and want to evangelise @matthewhaworth
  • 4. Magento 1 Architecture Review • The Active Record pattern implied that a Model was responsible for persisting data to the database through ->save() • However, the Model delegated to the Resource Model • The Resource Model iterated through the database table’s fields and pulled those keys from the Model to create an insert/update query. @matthewhaworth Model Resource Model ->save() ->save($this)
  • 5. Magento 1 Architecture Review • The Model was responsible for modelling the data. • The Resource Model was effectively a Data Mapper. • Any business logic was either in the Model or in a custom built service class @matthewhaworth
  • 6. Magento 2’s New Architecture • Magento 2 seeks to formalise this structure by introducing ‘Service Contracts’. • Service contracts are a set of interfaces defined for data models and services. @matthewhaworth
  • 8. Magento 2’s New Architecture • Data persistence within service contracts starts with the ’repository’. • “A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection.” – Martin Fowler @matthewhaworth
  • 9. No more abstract model! • Domain objects are now completely independent from the database! @matthewhaworth Model Abstract Model extends
  • 10. @matthewhaworth Magento 1 Magento 2 Model Abstract Model Resource Model Abstract Resource Model extends extends delegates database map and save Repository Interface Repository Implementation implements Data Interface Data Object Implementation implements is passed to repository for save
  • 11. @matthewhaworth Magento 1 Magento 2 Model Abstract Model Resource Model Abstract Resource Model extends extends delegates database map and save Resource Model Abstract Resource Model extends Repository Interface Repository Implementation implements Data Interface Data Object Implementation implements delegates database map and save is passed to repository for save
  • 12. Why move to repositories? • Separate the representation of data, business logic and data persistence • Beneficial for testing by allowing a substitution point for unit tests • Repository interfaces provides a version-able, single point of communication for APIs and other modular dependencies @matthewhaworth
  • 13. But wait, there’s a problem… The object passed to the resource must extend the Abstract Model public function save(MagentoFrameworkModelAbstractModel $object) @matthewhaworth Resource ModelRepository InterfaceData Interface
  • 14. So what are our options? 1. Implement data interface and extend the Abstract Model, sacrificing our new found independence. @matthewhaworth Data Object Abstract ModelData Interface implements extends
  • 15. So what are our options? 2. Implement the data interface and map to the Abstract Model in the repository before passing to the resource. @matthewhaworth Abstract Model Implementation Data Object Repository Resource map
  • 16. So what are our options? 3. Best of both worlds! Implement the data interface, the abstract model and map to the Abstract Model in the repository before passing to the resource. @matthewhaworth Model & Data Object Repository Resource 2. Map to data object Abstract ModelData Interface implements extends 1. Submit to save Model & Data Object
  • 17. So what are our options? 4. Use a different data persistence layer to the Magento DB Resource, maybe Doctrine? @matthewhaworth
  • 18. So what are our options? 4. Use a different data persistence layer to the Magento DB Resource, maybe Doctrine? @matthewhaworth Nah.
  • 19. For me, the clear winner is approach 3 • Implement the data interface and extend the abstract model • Map from the data interface to the abstract model in the repository • Avoids duplicating an extra model for the sake of pushing to the resource @matthewhaworth Model & Data Object Repository Resource 2. Map to data object Abstract Model Data Interface implementsextends 1. Submit to save Model & Data Object
  • 21. Where can I see good examples? Magento_Customer was regarded as the best example. This module maps its data interfaces to a separate Abstract Model implementation in its repository (approach 2). Multi Source Inventory (a set of modules) is currently regarded as the best example to follow. Data models in this module both implement the data interface and extend the data model (approach 3) and also make use of CQRS. (see MagentoInventoryModelStock @ github.com/magento-engcom/msi) @matthewhaworth
  • 22. What does the future look like? • Removing the Abstract Model entirely • Moving beforeSave(), afterSave(), etc to plugins and events (AOP) (They’re also making them ‘bulk-first’.) • Command Query Responsibility Segregation @matthewhaworth
  • 23. Thank you to Alan Kent, Anton Kril and Vinai Kopp @matthewhaworth Questions?