Patterns library
Design patterns
Design patterns are proven, reusable solutions to common software design problems, and a shared vocabulary for engineering teams. Below are the patterns I've applied in real projects, with examples in TypeScript and Python.
Creational
How objects get created.
- SingletonEnsure a class has only one instance and provide a global point of access to it.
- Factory MethodDefine an interface for creating an object, but let subclasses decide which class to instantiate.
- Abstract FactoryProduce families of related objects without specifying their concrete classes.
- BuilderConstruct complex objects step by step, separating construction from representation.
- PrototypeCreate new objects by copying an existing instance.
Structural
How objects are composed into larger structures.
- AdapterLet objects with incompatible interfaces work together.
- BridgeSplit an abstraction from its implementation so the two can vary independently.
- CompositeCompose objects into tree structures and treat individual objects and groups uniformly.
- DecoratorAttach new behaviour to an object dynamically by wrapping it.
- FacadeProvide a simple interface to a complex subsystem.
- FlyweightComing soonShare common state between many objects to save memory.
- ProxyProvide a placeholder that controls access to another object.
Behavioural
How objects communicate and share responsibility.
- Chain of ResponsibilityPass a request along a chain of handlers until one of them handles it.
- CommandTurn a request into a stand-alone object that can be queued, logged or undone.
- IteratorTraverse a collection without exposing its underlying representation.
- MediatorComing soonReduce coupling by making objects communicate through a central mediator.
- MementoComing soonCapture and restore an object's state without breaking encapsulation.
- ObserverNotify many dependent objects automatically when one object changes.
- StateLet an object change its behaviour when its internal state changes.
- StrategyDefine a family of interchangeable algorithms and choose one at runtime.
- Template MethodDefine an algorithm's skeleton and let subclasses override specific steps.
- VisitorComing soonAdd new operations to an object structure without changing its classes.