http://www.cnblogs.com/wuyuegb2312/archive/2013/04/09/3008320.html
==== 单例模式 ====
[[单例模式实现]]
public static void main(String[] args) {
Singleton single = Singleton.getInstance();
System.out.println(single3.about());
}
}
==== 工场模式 ====
public static void main(String[] args) {
FruitFactory factory = new FruitFactory();
Fruit apple = factory.create(Apple.class);
apple.getColor();
Fruit oringe = factory.create(Apple.class);
oringe.getColor();
}
==== 模板方法 ====
public static void main(String[] args) {
Fruit apple = new Apple(); // Fruit 是一个抽象类(水果类模板),所有水果都继承它
apple.getColor();
Fruit oringe = new Oringe();
oringe.getColor();
}
==== 代理模式 ====
[[代理模式详解]]
{{:python:pasted:20160328-203745.png}}
==== 中介者模式 ====
多对多模型时,不属于自己的业务全丢给中介处理
{{:python:pasted:20160328-211037.png}}
{{:python:pasted:20160328-210904.png}}
==== 责任链模式 ====
自己不能处理时交给下一级处理
{{:python:pasted:20160328-212127.png}}
Handle A_handle = new Handle();
Handle B_handle = new Handle();
Handle C_handle = new Handle();
A.setNextHandle(B);
B.setNextHandle(C);
==== 装饰模式 ====
Component c1 = new ConcreteComponent (); //首先创建需要被装饰的原始对象(即要被装饰的对象)
Decorator decoratorA = new ConcreteDecoratorA(c1); //给对象透明的增加功能A并调用
decoratorA .operation(); // decoratorA 对c1对象进行了装饰,
==== 适配器模式 ====
interface TwoSocket { // 二孔插头
public void twoSocket();
}
class ThreeSocket { // 三孔插头
public void threeSocket() {
System.out.println("i'm three socket");
}
}
public class Adapter extends ThreeSocket implements TwoSocket{ // 适配器,同时有二孔和三孔
public void twoSocket() { // 即使使用二孔插头也能插三孔插头
super.threeSocket();
}
public static void main(String[] args) {
TwoSocket t = new Adapter(); // 使用适配器
t.twoSocket();
}
}
==== 观察者模式 ====
[[观察者模式详解]]
==== 门面模式 ====
[[门面模式详解]]
{{:python:pasted:20160328-222136.png}}
==== 访问者模式 ====