常见设计模式总结
创建型模式
1. 单例模式 (Singleton)
public class Singleton {
private static Singleton instance;
private Singleton() {}
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}2. 工厂方法模式 (Factory Method)
3. 抽象工厂模式 (Abstract Factory)
4. 建造者模式 (Builder)
5. 原型模式 (Prototype)
结构型模式
1. 适配器模式 (Adapter)
2. 装饰器模式 (Decorator)
3. 代理模式 (Proxy)
4. 外观模式 (Facade)
5. 桥接模式 (Bridge)
6. 组合模式 (Composite)
7. 享元模式 (Flyweight)
行为型模式
1. 观察者模式 (Observer)
2. 策略模式 (Strategy)
3. 命令模式 (Command)
4. 状态模式 (State)
5. 责任链模式 (Chain of Responsibility)
6. 备忘录模式 (Memento)
7. 访问者模式 (Visitor)
8. 中介者模式 (Mediator)
9. 解释器模式 (Interpreter)
最后更新于