Gang of Four Design Patterns
The 23 design patterns catalogued by Gamma, Helm, Johnson and Vlissides in Design Patterns: Elements of Reusable Object-Oriented Software (1994).
Creational#
- Abstract Factory — provide an interface for creating families of related objects without specifying their concrete classes.
- Builder — separate the construction of a complex object from its representation, so the same process can create different representations.
- Factory Method — define an interface for creating an object, but let subclasses decide which class to instantiate.
- Prototype — create new objects by cloning an existing instance.
- Singleton — ensure a class has only one instance and provide a global point of access to it.
Structural#
- Adapter — convert the interface of a class into another interface clients expect.
- Bridge — decouple an abstraction from its implementation so the two can vary independently.
- Composite — compose objects into tree structures to represent part-whole hierarchies, letting clients treat individual objects and compositions uniformly.
- Decorator — attach additional responsibilities to an object dynamically, as an alternative to subclassing.
- Facade — provide a simplified interface to a complex subsystem.
- Flyweight — use sharing to support large numbers of fine-grained objects efficiently.
- Proxy — provide a surrogate or placeholder for another object to control access to it.
Behavioral#
- Chain of Responsibility — pass a request along a chain of handlers until one processes it.
- Command — encapsulate a request as an object, allowing parameterization, queuing, and undo.
- Interpreter — define a grammar and an interpreter that uses the grammar to interpret sentences.
- Iterator — access elements of a collection sequentially without exposing its underlying representation.
- Memento — capture an object’s internal state so it can be restored later without violating encapsulation.
- Mediator — define an object that encapsulates how a set of objects interact, promoting loose coupling.
- Observer — define a one-to-many dependency so that when one object changes state, all dependents are notified.
- Strategy — define a family of algorithms, encapsulate each one, and make them interchangeable at runtime.
- State — allow an object to alter its behavior when its internal state changes, appearing to change its class.
- Template Method — define the skeleton of an algorithm in a base class, letting subclasses override specific steps.
- Visitor — represent an operation to be performed on elements of an object structure without changing the classes.
