Design Patterns
The fundamental building blocks of object-oriented design, with the problem each one solves and where it shows up in real systems.
Creational
4 patternsHow objects get created without hard-wiring concrete classes.
- - instance
- + getInstance()
Singleton
#01Ensure a class has one instance and a global access point to it.
- + create(kind)
Factory
#02Let a method decide which concrete class to instantiate.
- + where(clause)
- + build()
Builder
#03Construct a complex object step by step.
- + clone()
Prototype
#04Create new objects by cloning an existing one.
Structural
4 patternsHow classes and objects compose into larger structures.
- - legacy: XmlApi
- + fetch()
Adapter
#05Make an incompatible interface work with the one clients expect.
- - inner: Stream
- + write(bytes)
Decorator
#06Attach behaviour to an object by wrapping it.
- + placeOrder(cart)
Facade
#07Give a complex subsystem one simple entry point.
- - real: Image
- + render()
Proxy
#08Control access to an object through a stand-in.
Behavioral
4 patternsHow responsibilities and communication are distributed.
- + subscribe(fn)
- + notify(e)
Observer
#09Notify dependents automatically when an object changes.
- + apply(total)
Strategy
#10Swap interchangeable algorithms behind one interface.
- + execute()
- + undo()
Command
#11Turn a request into an object you can queue, log or undo.
- + insertCoin()
- + dispense()
State
#12Change an object’s behaviour when its internal state changes.