创建型模式...
1. Abstract Factory..
2. Builder
3. Factory Method..
4. Prototype..
5. Singleton.
结构型模式...
1. Adapter.
2. Bridge..
3. Composite..
4. Decorator.
5. Facade..
6. Flyweight.
7. Proxy..
静态代理:
public class Tank implements Movable {
/**
* 模拟坦克移动了一段儿时间
*/
@Override
public void move() {
System.out.println("Tank moving claclacla...");
try {
Thread.sleep(new Random().nextInt(10000));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
class TankTimeProxy implements Movable {
Movable m;
public TankTimeProxy(Movable m) {
this.m = m;
}
@Override
public void move() {
long start = System.currentTimeMillis();
m.move();
long end = System.currentTimeMillis();
System.out.println(end - start);
}
}
class TankLogProxy implements Movable {
Movable m;
public TankLogProxy(Movable m) {
this.m = m;
}
@Override
public void move() {
System.out.println("start moving...");
m.move();
long end = System.currentTimeMillis();
System.out.println("stopped!");
}
}
interface Movable {
void move();
}
使用时
new TankLogProxy(
new TankTimeProxy(
new Tank()
)
).move();
行为模式...
1. Chain of Responsibility.
2. Command.
3. Interpreter.
4. Iterator
5. Mediator
6. Memento..
7. Observer
8. State..
9. Strategy.
10. Template Method..
11. Visitor.