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程序员极力推荐的springboot全家桶干货系列——收藏必会系列
    mysql 远程连接数据库的二种方法
    mysql取以当前时间为中心的任意时间段的时间戳
    使用sql语句,查询 mysql 的安装地址
    MyEclipse中点击Deploy MyEclipse J2EE Project to Server无响应解决方法
    使用DOS访问数据库详解
    mysql查询字段为null 返回0
    MySQL触发器Trigger实例篇
    JAVA汉字转拼音(取首字母大写)
    阿里云上传文件
  • 原文地址:https://www.cnblogs.com/antai/p/designPatternQuickMemo.html
Copyright © 2011-2022 走看看