本文的设计模式列表来源于github上人气比较高的iluwatar/java-design-patterns,包含了23种经典设计模式和很多实际应用中涉及到的模式。
“设计模式是程序员在设计应用程序时能够解决场景问题的最佳实现,通过经测试和验证的开发范例,可以提高开发效率。重用设计模式,可有效避免可能因细微问题而导致的重大隐患,同时有助于提升熟悉设计模式的编码人员和架构师对代码的可读性。”
模式列表
以下是设计模式列表,部分模式名直译成中文名可能比较晦涩难懂,所以没做中文解释。
本文模式类型分为:创建型(Creational)、结构型(Structural)、行为型(Behavioral)、架构型(Architectural)、并发型(Concurrency)、集成型(Integration)、业务层(Business Tier)、持久层(Persistence Tier)、表现层(Presentation Tier)和一些其他的类型。
| 模式名称 | 中文名称 | 模式类型 | 难度级别 |
|---|---|---|---|
| Abstract Document | 抽象文档 | 结构型(Structural) | 中级 |
| Abstract Factory | 抽象工厂 | 创建型(Creational) | 中级 |
| Adapter | 适配器 | 结构型(Structural) | 初级 |
| Aggregator Microservices | 微服务 | 架构型(Architectural) | 中级 |
| Api Gateway | API网关 | 架构型(Architectural) | 中级 |
| Async Method Invocation | 异步方法调用 | 并发型(Concurrency) | 中级 |
| Balking | 慢行 | 并发型(Concurrency) | 初级 |
| Bridge | 桥接 | 结构型(Structural) | 中级 |
| Builder | 构建者 | 创建型(Creational) | 中级 |
| Business Delegate | 业务代表 | 业务层(Business Tier) | 中级 |
| Caching | 高速缓存 | 其他(Other) | 中级 |
| Callback | 回调 | 其他(Other) | 初级 |
| Chain | 责任链 | 行为型(Behavioral) | 中级 |
| Command | 命令 | 行为型(Behavioral) | 中级 |
| Composite | 组合 | 结构型(Structural) | 中级 |
| Converter | 转换器 | 业务层(Business Tier) | 初级 |
| CQRS | 命令查询的责任分离 | 架构型(Architectural) | 中级 |
| Dao | 数据访问对象 | 持久层(Persistence Tier) | 初级 |
| Data Bus | 数据总线 | 架构型(Architectural) | 中级 |
| Data Mapper | 数据映射 | 持久层(Persistence Tier) | 初级 |
| Data Transfer Object | 数据传输对象 | 架构型(Architectural) | 初级 |
| Decorator | 装饰器 | 结构型(Structural) | 初级 |
| Delegation | 委托 | 行为型(Behavioral) | 初级 |
| Dependency Injection | 依赖注入 | 行为型(Behavioral) | 初级 |
| Double Checked Locking | 双重检查锁定 | 并发型(Concurrency) | 初级 |
| Double Dispatch | 双分派 | 其他(Other) | 中级 |
| EIP Aggregator | EIP聚合 | 集成型(Integration) | 中级 |
| EIP Splitter | EIP分离 | 集成型(Integration) | 中级 |
| EIP Wire Tap | EIP窃听 | 集成型(Integration) | 中级 |
| Event Aggregator | 事件聚合 | 结构型(Structural) | 初级 |
| Event-based Asynchronous | 基于事件的异步 | 并发型(Concurrency) | 中级 |
| Event Driven Architecture | 事件驱动架构 | 架构型(Architectural) | 中级 |
| Event Queue | 事件队列 | 并发型(Concurrency) | 中级 |
| Event Sourcing | 事件溯源 | 架构型(Architectural) | 中级 |
| Execute Around | 执行环绕 | 其他(Other) | 初级 |
| Extension objects | 扩展对象 | 行为型(Behavioral) | 中级 |
| Facade | 外观 | 结构型(Structural) | 初级 |
| Factory Kit | 简单工厂 | 创建型(Creational) | 初级 |
| Factory Method | 工程方法 | 创建型(Creational) | 初级 |
| Feature Toggle | 功能开关 | 行为型(Behavioral) | 初级 |
| Fluent Interface | 流接口 | 其他(Other) | 中级 |
| Flux | 单向数据流 | 表现层(Presentation Tier) | 中级 |
| Flyweight | 享元 | 结构型(Structural) | 中级 |
| Front Controller | 前端控制器 | 表现层(Presentation Tier) | 中级 |
| Guarded Suspension | 保护性挂起 | 并发型(Concurrency) | 初级 |
| Half-Sync/Half-Async | 半同步半异步 | 并发型(Concurrency) | 中级 |
| Hexagonal Architecture | 六边形架构 | 架构型(Architectural) | 高级 |
| Intercepting Filter | 拦截过滤器 | 行为型(Behavioral) | 中级 |
| Interpreter | 解释器 | 行为型(Behavioral) | 中级 |
| Iterator | 迭代 | 行为型(Behavioral) | 初级 |
| Layers | 分层 | 架构型(Architectural) | 中级 |
| Lazy Loading | 延迟加载 | 其他(Other) | 初级 |
| Marker Interface | 标记接口 | 其他(Other) | 初级 |
| Mediator | 中介者 | 行为型(Behavioral) | 中级 |
| Memento | 备忘录 | 行为型(Behavioral) | 中级 |
| Message Channel | 消息通道 | 集成型(Integration) | 中级 |
| Model-View-Controller | 模型-视图-控制 | 表现层(Presentation Tier) | 中级 |
| Model-View-Presenter | 模型-视图-演示 | 表现层(Presentation Tier) | 中级 |
| Module | 模块 | 创建型(Creational) | 初级 |
| Monad | 单子 | 其他(Other) | 高级 |
| MonoState | 单态 | 创建型(Creational) | 初级 |
| Multiton | 多例 | 创建型(Creational) | 初级 |
| Mute Idiom | 其他(Other) | 初级 | |
| Mutex | 互斥 | 并发型(Concurrency) | 中级 |
| Naked Objects | 无装饰对象 | 架构型(Architectural) | 高级 |
| Null Object | 零对象 | 行为型(Behavioral) | 初级 |
| Object Mother | 创建型(Creational) | 初级 | |
| Object Pool | 对象池 | 创建型(Creational) | 初级 |
| Observer | 观察者 | 行为型(Behavioral) | 初级 |
| Page Object | 页面对象 | 其他(Other) | 中级 |
| Partial Response | 部分响应 | 架构型(Architectural) | 初级 |
| Poison Pill | 其他(Other) | 中级 | |
| Private Class Data | 私有类数据 | 其他(Other) | 初级 |
| Producer Consumer | 生产者-消费者 | 并发型(Concurrency) | 中级 |
| Promise | 并发型(Concurrency) | 中级 | |
| Property | 属性 | 创建型(Creational) | 初级 |
| Prototype | 原型 | 创建型(Creational) | 初级 |
| Proxy | 代理 | 结构型(Structural) | 初级 |
| Publish Subscribe | 发布者-订阅者 | 集成型(Integration) | 中级 |
| Queue based load leveling | 基于队列的负载均衡 | 其他(Other) | 中级 |
| Reactor | 反应器 | 并发型(Concurrency) | 高级 |
| Reader Writer Lock | 读写锁 | 并发型(Concurrency) | 中级 |
| Repository | 资源库 | 表现层(Presentation Tier) | 中级 |
| Resource Acquisition Is Initialization | 资源初始化 | 其他(Other) | 初级 |
| Retry | 重试 | 其他(Other) | 高级 |
| Semaphore | 信号 | 并发型(Concurrency) | 中级 |
| Servant | 服务者 | 结构型(Structural) | 初级 |
| Service Layer | 服务分层 | 架构型(Architectural) | 中级 |
| Service Locator | 服务定位器 | 结构型(Structural) | 初级 |
| Singleton | 单例 | 创建型(Creational) | 初级 |
| Specification | 规约 | 行为型(Behavioral) | 初级 |
| State | 状态 | 行为型(Behavioral) | 中级 |
| Step Builder | 步骤构建者 | 创建型(Creational) | 中级 |
| Strategy | 策略 | 行为型(Behavioral) | 初级 |
| Template method | 模板方法 | 行为型(Behavioral) | 初级 |
| Thread Pool | 线程池 | 并发型(Concurrency) | 中级 |
| Throttling | 节流 | 行为型(Behavioral) | 初级 |
| Thread Local Storage | 线程本地存储 | 并发型(Concurrency) | 中级 |
| Tolerant Reader | 读者容错 | 集成型(Integration) | 初级 |
| Trampoline | 行为型(Behavioral) | 中级 | |
| Twin | 双胞胎 | 创建型(Creational) | 中级 |
| Unit Of Work | 工作单元 | 架构型(Architectural) | 初级 |
| Value Object | 值对象 | 创建型(Creational) | 初级 |
| Visitor | 访问者 | 行为型(Behavioral) | 中级 |