weirenxue / dp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Design Pattern


  1. Creational patterns

    Provide object creation mechanisms that increase flexibility and reuse of exisiting code.

    1. Builder: When piecewise object construction is complicated, provide an API for doing it succinctly.
    2. Factory: A component responsible solely for the wholesale (not piecewise) creation of objects.
    3. Prototype: A partially or fully initialized object that you copy (clone) and make use of.
    4. Singleton: A component which is instantiated only once.
  2. Structural patterns

    Explain how to assemble objects and classes into larger structures, while keeping these structures flexible and efficient.

    1. Adapter: A construct which adapts an existing interface X to conform to the required interface Y.
    2. Bridge: A mechanism that decouples an interface (hierarchy) from an implementation (hierarchy).
    3. Composite: A mechanism for treating individual (scalar) objects and compositions of objects in a uniform manner.
    4. Decorator: Facilitates the addition of behaviors to individual objects through embedding.
    5. Facade: Provides a simple, easy to understand/use interface over a large and sophisticated body of code.
    6. Flyweight: A space optimization technique that lets us use less memory by storing externally the data associated with similar objects.
    7. 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.
  3. Behavioral patterns

    Take care of effective communication and the assignment of responsibilities between objects.

    1. 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.
    2. Command: An object which represents an instruction to perform a particular action. Contains all the information necessary for the action to be taken.
    3. 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).
    4. Iterator: An object that facilitates the traversal of a data structure.
    5. 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.
    6. 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.
    7. 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.
    8. 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.
    9. Strategy: Seperates an algorithm into its 'skeleton' and concrete implementation steps, which can be varied at run-time.
    10. Template Method: A skeleton algorithm defined in a function. Function can either use an interface (like Strategy) or can take serveral functions as arguments.
    11. 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.

About


Languages

Language:Go 100.0%