Idea | Type | Categories | Patterns |
---|---|---|---|
parameterize a system by the classes of objects it creates | Creational | Subclassing - Object Composition | Factory Method - Abstract Factory, Builder, Prototype |
provide a level of indirection | Structural | Before the fact - After the fact - Properties - Stand-in | Bridge - Adapter - Decorator - Proxy |
recursive composition to organize an open-ended number of objects | Structural | Treatment - Responsibility | Composite - Decorator |
Encapsulating Variation | Behavioral | Algorithm - State-dependent behavior - Protocol - Traversal | Strategy - State - Mediator - Iterator |
Objects as Arguments | Behavioral | Polymorphic operation - Request - State | Visitor - Command - Memento |
Communication | Behavioral | Encapsulated - Distributed | Mediator - Observer |
Decoupling Senders and Receivers | Behavioral | Binding - Signaling - Indirect reference - Percolating | Command - Observer - Mediator - Chain of responsibility |
Finding Appropriate Objects | Abstracting Reality | Treat objects uniformly - Interchangeable families of algorithms - State of an entity as an object | Composite - Strategy - State |
Determining Object Granularity | Abstracting Reality | Represent complete subsystem as object - Support huge numbers of objects at the finest granularities - Creating other objects - Implement a request on another object or group of objects | Facade - Flyweight - Abstract Factory, Builder - Visitor, Command |
Specifying Object Interfaces | Abstracting Reality | Encapsulate internal state of an object - Identical interfaces - Reflect classes | Memento - Decorator, Proxy - Visitor |
Class vs. Interface (subclass vs. subtype) | Specifying Object Implementations | Subclass - Subtype - Abstract class | Composite - Chain of Responsibility - Command, Observer, State, Strategy |
Delegation (of a request) | Specifying Object Implementations | To an object that represents state - To an object that represents algorithm - To an object that traverses structure | State - Strategy - Visitor |
Avoiding change-induced problems | Designing for Change |
Problem:
|
|
Purpose | ||||
---|---|---|---|---|
Creational | Structural | Behavioral | ||
Scope | Class | Factory Method | Adapter | Interpreter Template Method |
Object | Abstract Factory Builder Prototype Singleton |
Adapter Bridge Composite Decorator Facade Proxy |
Chain of Responsibility Command Iterator Mediator Memento Flyweight Observer State Strategy Visitor |
Purpose | Design Pattern | Aspect(s) That Can Vary |
---|---|---|
Creational | Abstract Factory | families of product objects |
Builder | how a composite object gets created | |
Factory Method | subclass of object that is instantiated | |
Prototype | class of object that is instantiated | |
Singleton | the sole instance of a class | |
Structural | Adapter | interface to an object |
Bridge | implementation of an object | |
Composite | structure and composition of an object | |
Decorator | responsibilities of an object without subclassing | |
Facade | interface to a subsystem | |
Flyweight | storage costs of objects | |
Proxy | how an object is accessed; its location | |
Behavioral | Chain of Responsibility | object that can fulfill a request |
Command | when and how a request is fulfilled | |
Interpreter | grammar and interpretation of a language | |
Iterator | how an aggregate's elements are accessed, traversed | |
Mediator | how and which objects interact with each other | |
Memento | what private information is stored outside an object, and when | |
Observer | number of objects that depend on another object; how the dependent objects stay up to date | |
State | states of an object | |
Strategy | an algorithm | |
Template Method | steps of an algorithm | |
Visitor | operations that can be applied to object(s) without changing their class(es) |
Program to an interface, not an implementation. Creational patterns let you abstract the process of object creation; you can associate an interface with its implementation transparently at instantiation.