-
Creational patterns
Provide object creation mechanisms that increase flexibility and reuse of exisiting code.
- Builder: When piecewise object construction is complicated, provide an API for doing it succinctly.
- Factory: A component responsible solely for the wholesale (not piecewise) creation of objects.
- Prototype: A partially or fully initialized object that you copy (clone) and make use of.
- Singleton: A component which is instantiated only once.
-
Structural patterns
Explain how to assemble objects and classes into larger structures, while keeping these structures flexible and efficient.
- Adapter: A construct which adapts an existing interface X to conform to the required interface Y.
- Bridge: A mechanism that decouples an interface (hierarchy) from an implementation (hierarchy).
- Composite: A mechanism for treating individual (scalar) objects and compositions of objects in a uniform manner.
- Decorator: Facilitates the addition of behaviors to individual objects through embedding.
- Facade: Provides a simple, easy to understand/use interface over a large and sophisticated body of code.
- Flyweight: A space optimization technique that lets us use less memory by storing externally the data associated with similar objects.
- Proxy: A type that functions as an interface to a particular resource. That resource may be remote, expensive to construct, or may require logging or some other added functionality.
-
Behavioral patterns
Take care of effective communication and the assignment of responsibilities between objects.
- Chain of Responsibility: A chain of components who all get a chance to process a command or a query, optionally having default processing implementation and an ability to terminate the processing chain.
- Command: An object which represents an instruction to perform a particular action. Contains all the information necessary for the action to be taken.
- Interpreter: A component that processes structured text data. Does so by turning it into separate lexical tokens (lexing) and then interpreting sequences of said tokens (parsing).
- Iterator: An object that facilitates the traversal of a data structure.
- Mediator: A component that facilitates communication between other components without them necessarily being aware of each other or having direct (reference) access to each other.
- Memento: A token representing the system state. Lets us roll back to the state when the token was generated. May or may not directly expose state information.
- Observer: An observer is an object that wishes to be informed about events happening in the system. The entity generating the events is an observable.
- State: A pattern in which the object's behavior is determined by its state. An object transitions from one state to another (something needs to trigger a transition). A formalized construct which manages state and transitions is called a state machine.
- Strategy: Seperates an algorithm into its 'skeleton' and concrete implementation steps, which can be varied at run-time.
- Template Method: A skeleton algorithm defined in a function. Function can either use an interface (like Strategy) or can take serveral functions as arguments.
- Visitor: A pattern where a component (visitor) is allowed to traverse the entire hierarchy of types. Implemeneted by propagating a single Accept() method throughout the entire hierachy.