Observer and Strategy are two of the most widely used behavioural patterns. Observer defines a publish-subscribe mechanism where subjects notify observers of state changes. Strategy defines a family of interchangeable algorithms. Both appear throughout Magento 2 – I show GoF implementations and the platform’s concrete use of each.
Adapter and Facade are two structural patterns that manage complexity at the boundaries of a system. Adapter makes incompatible interfaces work together. Facade simplifies a complex subsystem behind a clean, high-level interface. Both appear constantly in real PHP projects – I show implementations and concrete examples from Magento 2.
Decorator and Proxy look similar at first glance – both wrap another object and implement the same interface. The intent is different. Decorator adds new behaviour. Proxy controls access. This post covers both structural patterns in depth, with PHP implementations, concrete use cases, and a comparison that clarifies when to reach for each one.
Singleton and Builder are two more creational patterns from the GoF catalogue. Singleton is probably the most controversial – often misused, but legitimate in specific contexts. Builder shines when constructing complex objects with many optional parameters. I show both with PHP implementations, pitfalls, and practical examples.
Factory Method and Abstract Factory are both creational patterns that remove the new keyword from business logic – but they solve different problems. Factory Method delegates creation to subclasses. Abstract Factory creates families of related objects. I implement both from scratch, compare them in a table, and show where Simple Factory fits as a pragmatic alternative.
Design patterns are reusable solutions to recurring design problems. The Gang of Four book from 1994 catalogued 23 patterns split into three categories. They are not code snippets to paste in – they are a vocabulary for communicating design decisions. This post is an introduction and reference table before I cover each pattern individually in the coming weeks.
SOLID principles are five design guidelines that make object-oriented code maintainable, extensible, and testable. They are not rules to be applied mechanically but tools for reasoning about design decisions. I show each principle in PHP with a before/after example and a concrete connection to Magento 2 architecture.
PHP 8.1 was released in November 2021. After a month of migrating modules and writing new code with the new features I have a clear view of what matters in practice. Enums are the biggest quality-of-life improvement – I show how I store them in the database, use them in match expressions, and build a Money value object that shows readonly properties and enums working together.
Chain of Responsibility passes a request along a chain of handlers. Each handler decides whether to process it or pass it on. The pattern is perfect for multi-step validation, middleware pipelines, and request processing where the set of handlers needs to change without modifying callers. I build a validator chain in PHP and show how to configure handler order through Magento 2 di.xml.
Redis in Magento 2 is not a single thing – it serves three distinct roles that should ideally run as separate instances with different configurations. Object cache, Full Page Cache, and session storage have very different access patterns and eviction requirements. I show how to configure each, why separate instances matter, and how to monitor what is happening.
