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.)

  • 相关阅读:
    关于python的类成员方法允许静态调用的机制
    一个pyqt5动态加载ui+多线程+信号刷新界面的例子
    一个经典的redis队列简单解决方案
    关于连表查询的执行计划
    electron nativefier打包网址 electron-winstaller制作安装包
    MySQL 8.0 字符串比较特殊案例小结
    MySQL SELECT_LEX与subselect 执行 源码阅读笔记
    MySQL 8.0 QueryResolver 源码笔记
    MySQL 8.0 Optimizer 源码笔记
    MySQL Item 源码阅读笔记
  • 原文地址:https://www.cnblogs.com/antai/p/designPatternQuickMemo.html
Copyright © 2011-2022 走看看