
design pattern
文章平均质量分 77
vcycyv
这个作者很懒,什么都没留下…
展开
-
bridge(转载)
/** "Implementor" */ interface DrawingAPI { public void drawCircle(double x, double y, double radius); } /** "ConcreteImplementor" 1/2 */ class DrawingAPI1 implements DrawingAPI { public void drawCircle(double x, double y, double radius) {转载 2011-02-08 17:27:00 · 180 阅读 · 0 评论 -
fly weight
单纯fly weight 1: //抽象享元角色 2: abstract public class Flyweight 3: { 4: abstract public void operation(String state); 5: } 6: 1: //具体享元(ConcreteFlyweight)角色转载 2011-02-12 23:57:00 · 236 阅读 · 0 评论 -
command
参考 http://en.wikipedia.org/wiki/Command_pattern /*the Invoker class*/public class Switch { private Command flipUpCommand; private Command flipDownCommand; public Switch(Command flipUpCmd, Command flipDownCmd) { this.flip转载 2011-02-12 23:24:00 · 225 阅读 · 0 评论 -
composite(转)
Motivation When dealing with tree-structured data, programmers often have to discriminate between a leaf-node and a branch. This makes code more complex, and therefore, error prone. The solution is an interface that allows treating complex and primitive o转载 2011-02-13 20:20:00 · 238 阅读 · 0 评论 -
串讲23种设计模式
零零碎碎地,学习过很多轮设计模式。总是学过就忘。后来就在google docs上做了一系列笔记,方便复习。最近把这些笔记搬家到blogjava上了,一边搬家,一边又复习一遍。学习设计模式有两个意义: 一、学习设计模式最重要的是了解模式的应用场景。编程遇到特定场景的话,要有意识联想到设计模式,哪怕细节忘了也没关系,翻翻书就找到了。 二、提高设计的思想。学习设计模式的时候,要体会模式精妙之处,当想明白大师思想和自己的差距的时候,差距就缩短了一点儿。 有的模式平淡无奇,应用却广泛。有的模式设计精巧,应用场景原创 2011-02-15 22:44:00 · 267 阅读 · 0 评论 -
abstract factory(转)
转载自 http://www.javaeye.com/topic/413580#1064514 一家公司生产两个系列的产品 A系列, 食品里: milk,meat,noodle B系列, 与A系列相对应的餐具,Spoon,Knife,Chopsticks 产品有两个系列,在A系列某个位置的产品,在B系列一定有一个对应的产品, 牛奶--汤勺, 肉-刀, 面条--筷子 抽象产品系列之一, 食品类接口与三个具体的食品类 1: package Foo原创 2011-02-15 21:11:00 · 151 阅读 · 0 评论 -
factory method
基本概念 FactoryMethod是一种创建性模式,它定义了一个创建对象的接口,但是却让子类来决定具体实例化哪一个类.当一个类无法预料要创建哪种类的对象或是一个类需要由子类来指定创建的对象时我们就需要用到Factory Method 模式了.简单说来,Factory Method可以根据不同的条件产生不同的实例,当然这些不同的实例通常是属于相同的类型,具有共同的父类.Factory Method把创建这些实例的具体过程封装起来了,简化了客户端的应用,也改善了程序的扩展性,使得将来可以做最小的改动就可以加转载 2011-02-13 11:29:00 · 187 阅读 · 0 评论 -
chain of responsibility
The following Java code illustrates the pattern with the example of a logging class. Each logging handler decides if any action is to be taken at this log level and then passes the message on to the next logging handler. The output is: Writing to stdout:转载 2011-02-12 23:16:00 · 190 阅读 · 0 评论 -
Mediator(转载)
一、 模式定义: 用一个中介者对象来封装一系列的对象交互。中介者使各对象不需要显式的相互引用,从而使其耦合松散,而且可以独立的改变他们之间的交互。 二、 结构图 (略) 1) 抽象中介者:定义同事(Colleague)对象到中介者(Mediatior)对象的接口,通常是一个事件方法。 2) 具体中介者:具体中介者实现抽象中介者声明的方法。知晓所有的具体同事类,从具体同事接收消息向另外的具体同事类发送命令。 3) 抽象同事类:定义中介者到同事对象的接口,同事对象只转载 2011-02-08 17:32:00 · 139 阅读 · 0 评论 -
state(转)
state模式 一、State模式定义: 允许一个对象在其状态改变时,改变它的行为。看起来对象似乎修改了它的类。 二、模式解说 State模式主要解决的是在开发中时常遇到的根据不同的状态需要进行不同的处理操作的问题,而这样的问题,大部分人是采用switch-case语句进行处理的,这样会造成一个问题:分支过多,而且如果加入一个新的状态就需要对原来的代码进行编译。State模式采用了对这些不同的状态进行封装的方式处理这类问题,当状态改变的时候进行处理然后再切换到另一种状态,也就是说把状态的切换转载 2011-02-09 23:07:00 · 133 阅读 · 0 评论 -
memento(转载)
备忘录(Memento Pattern)模式 备忘录模式又叫做快照模式(Snapshot Pattern)或Token模式,是对象的行为模式。 备忘录对象是一个用来存储另外一个对象内部状态的快照的对象。备忘录模式的用意是在不破坏封装的条件下,将一个对象的状态捕捉住,并外部化 存储起来,从而可以在将来合适的时候把这个对象还原到存储起来的状态。备忘录模式常常与命令模式和迭代子模式一同使用。 常见的软件系统往往不止存储一个状态,而是需要存储多个状态。这些状态常常是一个对象历史发展的不转载 2011-02-08 16:48:00 · 192 阅读 · 0 评论 -
decorator(转)
参考: http://en.wikipedia.org/wiki/Decorator_pattern Motivation UML Diagram for the Window Example As an example, consider a window in a windowing system. To allow scrolling of the window's contents, we may wish to add horizontal or vertical scrollb转载 2011-02-09 22:58:00 · 158 阅读 · 0 评论 -
builder(转载)
Builder Abstract interface for creating objects (product). Concrete Builder Provide implementation for Builder. Construct and assemble parts to build the objects. Director The Director class is responsible for managing the correct sequence of object c转载 2011-02-09 22:41:00 · 131 阅读 · 0 评论 -
visitor
参考:http://en.wikipedia.org/wiki/Visitor_pattern Example The following example is in the Java programming language, and shows how the contents of a tree of nodes (in this case describing the components of a car) can be printed. Instead of creating "pri转载 2011-02-13 14:18:00 · 196 阅读 · 0 评论