A little learning repo I've created for myself, exploring a couple of patterns from the Design Patterns: Elements of Reusable Object-Oriented Software that could be relevant for PHP (with some examples).
A design pattern is a proven technique which helps solve a recurring problem in software design. Each design pattern helps maximize code reuse and lets some aspect of system vary independently of other aspects, thereby making the system more robust to a particular type of change and facilitating other good coding principles, like SOLID.
Design patterns are classified into 3 distinct categories:
- Creational Patterns - provide flexible object creation mechanisms.
- Structural Patterns - assemble objects into flexible structures.
- Behavioral Patterns - ensure flexible communication and proper responsibility allocation among objects.
Some of the patterns I've explored here - and aspects that can vary freely without introducing breaking changes in the system.
Creational Patterns:
- Abstract Factory - families of objects
- Factory Method - subclass of an object that is instantiated
- Builder - how a composite object gets created
Structural Patterns:
- Adapter - instance of an object
- Decorator - responsibilities of an object, without subclassing it
- Composite - structure and composition of an object
- Facade - interface to a subsystem
- Bridge - implementation of an object
Behavioral Patterns:
- Strategy - the exact algorithm used
- State - state of an object
- Observer - number of objects that depend on an other object (subject), and how those dependent object stay up to date with the subject
- Command - when and how a request is fulfilled
- Template Method - steps of an algorithm
- Iterator - how an aggregate object's elements are accessed/traversed
- Chain of Responsibility - which object fulfills the request