Abstract factory |
You want to create objects of a selected family of classes but you don’t want the client to be affected by the choice. |
Adapter |
You want to convert one interface to another because they do not match and cannot be changed. |
Bridge |
You want to switch between different implementations at run time without affecting the client. |
Builder |
You want an abstraction of a process and a set of steps to build a product so that you can combine implementations of the two at run time to produce various categories of products using different processes. |
Chain of responsibility |
You want to pass a request along a reconfigurable chain of handlers until one that handles it. |
Command |
You want to encapsulate requests as (command) objects so that you can: (1) delegate the requests to the command objects, (2) queue the requests and execute them at a different time, (3) generate a plan of actions dynamically, and/or (4) stack the requests to support undo and redo. |
Composite |
You want to represent components with recursive part-whole relationships and allow the client to interact with components and composites uniformly. |
Decorator |
You want to dynamically add/remove functionality to/from objects. |
Facade |
You want to simplify a client's interface and interaction to a web of components. |
Factory method |
You want to create/use objects of a chosen class but you don't want to know, make, or be affected by the choice. |
Flyweight |
You want to save time and space incurred in the creation, initialization, and storage of many occurrences of an object. |
Interpreter |
You want dynamic modification of a portion of your program but you don't want to recompile the system. |
Iterator |
You want a traversal mechanism that hides the structure traversed. |
Mediator |
You want to replace m-m or component to component interaction with m-1 or component to mediator interaction. |
Memento |
You want to store and restore the state of an object but you don't want to expose the internals of the state to a third party. |
Observer |
You want to decouple change and related responses so that you can add or remove such dependencies freely and dynamically. |
Prototype |
You want to: (1) reduce object creation and initialization costs, (2) reduce number of classes, or (3) use dynamically loaded classes. |
Proxy |
You want to: (1) hide the use of a remote object, (2) defer creation of an object until it is actually used, (3) control access to an object, or (4) keep track of references or update to an object. |
Singleton |
You want to create at most one or a limited number of globally accessible instances of a class. |
State |
You want a low complexity and easy to extend solution to implement a state machine. |
Strategy |
You want to let the client select an algorithm from available algorithms to accomplish a given task. |
Template method |
You want the steps of a computation to vary but you don't want to do so with conditional statements. |
Visitor |
You want to decouple certain functionality from a class structure so that it can be applied to other class structures as well. |
龚老师的总结