zoukankan      html  css  js  c++  java
  • Design Patterns Quick Memo

    [Creational Patterns]

    Abstract factory: use generic interface, client doesn't know which concrete class is being instantiated

    Builder: step by step build something, example: building a house, making subway sandwich

    Factory:

    prototype: 从现有的几个代表形clone新的, example: map editor

    singleton:仅一个instance。。static元素的继承问题??

    [Structural Patterns]

    adapter: 把不同的接口适应化

    bridge:分离主体和具体的implemenation, example:问卷调查template+具体问卷问题

    composite: 文件和文件的相互包含和层级关系, example: 文件系统

    decorator:不同的窗口的美化,scroller/frame,添加一个水平线在subclass

    facade:加一个统一的中间接口,隔离外界和子系统,e.g. compiler system

    flight weight, 游戏引擎中对sprite的复用, reuse state,event

    proxy: e.g.编辑器/浏览器里,读取图像文件失败时显示的红叉叉

    [Behavioral Patterns]

    chain of responsibility: one of the item in the open list is gonna handle the problem, which is opaque to the outside

    command: queue/log request, a list/buffer..

    interpreter: regex

    iterator: traverse stuff, C++ STL, Java

    mediator:租房,求房,(同辈之间)透过中介的关系; 按钮被另一个组建dictates

    memento: save/screen shot a particular state of the subject

    observer(subscription): flash, eventlistener thing; C++, delegation.

    state: multiply states act according to same interface(e.g. TCPState, GameState, AI, animation tree)

    strategy: a family of algorithm to solve a certain problem, encapsulated each one.  (e.g. textEditor, linebreaker??)

    http://en.wikipedia.org/wiki/Strategy_pattern

    template method: the most basic/common use of inheritance

    Visitor: allow outside functionalities to be executed

    class Element {
      Accept(Visitor visitor)  {
        visitor.Visit(this);
      }
    }
    
    class Visitor {
      Visit(Element element) {
        //Do something
        ...     } }

    (NOTICE: while virtual functions are dispatched dynamically in C++, function overloading is done statically.)

  • 相关阅读:
    Java进阶 -- 文章汇总
    Java并发编程 -- 文章汇总
    大话设计模式读书笔记--文章汇总
    Java并发编程--6.Exchanger线程间交换数据
    Java并发编程--7.Java内存操作总结
    Java并发编程--5.信号量和障碍器
    Java并发编程--4.Executor框架
    Java并发编程--3.Lock
    Java并发编程--2.synchronized
    Java并发编程--1.Thread和Runnable
  • 原文地址:https://www.cnblogs.com/antai/p/designPatternQuickMemo.html
Copyright © 2011-2022 走看看