During Magento Meetup 13 which took place in Dublin, Ireland at February 9, 2016 I’ve had a chance to share thoughts about Design Patterns usage in Magento 2.
I’ve uploaded presentation to SlideShare website. Feel free to share your experience using Design Patterns in Magento 2.
I decided to start from Magento 2 architectural goals. The goals were set few years ago for Magento 2 project:
- Streamline customizations. With this goal developers are able to spend less time implementing frontend and backend features. This goal also comes from Magento 1 development where developers should literally copy-paste big chankes of templates and code in order to customize it. Or in case new field or attribute should be added.
- Simplify external integrations. This goal helps to address reduce complexity when it comes to integrations with 3rd party services (e.g. Payment Service Providers, Shipping Providers, Mobile Apps etc.).
How it is solved in Magento 2
Loose coupling between modules. Over the last year before the official Magento 2.0 GA release all teams were working on reducing complexity in Magento modules. It resulted in higher amount of tiny modules with less cross-module dependencies.
SOLID Principles. One of main for my point of view decisions was to accept usage of 5 main object oriented design principles. Thanks to @AntonKril who is now Magento 2 Architect. Anton broadcasted (I hope this is a right word) to every single developer who worked on Magento 2. Would this happens occasionally without him? I don’t know. Maybe few month later.
Design Patterns. In Magento 2 you may find tons of Design Patterns starting from Gang of Four Design Patterns, Enterprise Patterns by Martin Fawler. Sometimes I see overuse of some Design Patterns.
Configuration over customization. With the Inversion of Control Design Pattern and Object Manager implementation the real power of Dependency Injection become available for Magento developers. Now, in Magento 2 you are free to set preference class when you use interface. Or configure virtual type (which is also class created dynamically) with custom constructor arguments.
These are good ways to reduce amount of code developer should write each time.
- Detailed explanation about SOLID Principles
- You may want to read from official Magento Documentation space about Magento 2 Architecture
- Alan Storm post about Magento 2 Patterns Patterns
- Post about SOLID Principles where I borrowed one image
Max Pronko is an international Magento Expert, development consultant, motivational speaker and Magento award-winning developer. He is known for the educational development programs for organizations of all sizes and has positively affected thousands of people and organizations worldwide.
Subscribe to my Magento 2 tips and tutorials content.
Every week I send an interesting email directly to your inbox