Loading...
Loading...
Compare original and translation side by side
| Pattern | Intent |
|---|---|
| Factory Method | Delegate object creation to subclasses |
| Abstract Factory | Create families of related objects without concrete types |
| Builder | Construct complex objects step-by-step |
| Prototype | Clone existing objects instead of building from scratch |
| Singleton | Ensure exactly one instance with global access |
references/CREATIONAL.md| 模式 | 意图 |
|---|---|
| Factory Method | 将对象创建委托给子类 |
| Abstract Factory | 创建相关对象族,无需指定具体类型 |
| Builder | 分步构建复杂对象 |
| Prototype | 克隆现有对象而非从零构建 |
| Singleton | 确保全局仅存在一个实例并提供全局访问 |
references/CREATIONAL.md| Pattern | Intent |
|---|---|
| Adapter | Make incompatible interfaces work together |
| Bridge | Separate abstraction from implementation |
| Composite | Treat individual objects and compositions uniformly |
| Decorator | Attach responsibilities dynamically without subclassing |
| Facade | Simplify complex subsystem with a unified interface |
| Flyweight | Share common state to reduce memory across many objects |
| Proxy | Control access to an object through a substitute |
references/STRUCTURAL.md| 模式 | 意图 |
|---|---|
| Adapter | 使不兼容的接口能够协同工作 |
| Bridge | 将抽象与实现分离 |
| Composite | 统一对待单个对象和对象组合 |
| Decorator | 在不使用子类化的情况下动态添加职责 |
| Facade | 用统一接口简化复杂子系统 |
| Flyweight | 共享公共状态以减少大量对象的内存占用 |
| Proxy | 通过代理对象控制对目标对象的访问 |
references/STRUCTURAL.md| Pattern | Intent |
|---|---|
| Chain of Responsibility | Pass requests along a handler chain |
| Command | Encapsulate requests as objects for queuing/undo |
| Iterator | Traverse collections without exposing internals |
| Mediator | Centralize complex communication between objects |
| Memento | Capture and restore object state |
| Observer | Notify dependents automatically on state changes |
| State | Alter behavior when internal state changes |
| Strategy | Swap algorithms at runtime |
| Template Method | Define algorithm skeleton, let subclasses override steps |
| Visitor | Add operations to objects without modifying them |
references/BEHAVIORAL.md| 模式 | 意图 |
|---|---|
| Chain of Responsibility | 沿着处理者链传递请求 |
| Command | 将请求封装为对象,用于排队/撤销操作 |
| Iterator | 遍历集合而无需暴露内部实现 |
| Mediator | 集中处理对象间的复杂通信 |
| Memento | 捕获并恢复对象状态 |
| Observer | 状态变化时自动通知依赖对象 |
| State | 内部状态变化时改变行为 |
| Strategy | 运行时切换算法 |
| Template Method | 定义算法骨架,让子类重写步骤 |
| Visitor | 在不修改对象的情况下为对象添加操作 |
references/BEHAVIORAL.md| Problem | Pattern(s) |
|---|---|
| Need to decouple object creation | Factory Method, Abstract Factory |
| Complex object with many optional fields | Builder |
| Expensive object creation, need copies | Prototype |
| Global shared resource (config, pool) | Singleton |
| Incompatible third-party interface | Adapter |
| Multiple dimensions of variation | Bridge |
| Tree structures (files, UI, org charts) | Composite |
| Add features without subclassing | Decorator |
| Simplify complex API surface | Facade |
| Thousands of similar objects, memory heavy | Flyweight |
| Lazy loading, access control, caching | Proxy |
| Flexible request processing pipeline | Chain of Responsibility |
| Undo/redo, task queues, macros | Command |
| Custom collection traversal | Iterator |
| Many-to-many object communication | Mediator |
| Snapshots, save/restore state | Memento |
| Event systems, reactive updates | Observer |
| Object behavior depends on its state | State |
| Swappable algorithms (sort, compress, etc) | Strategy |
| Algorithm with fixed steps, variable parts | Template Method |
| Operations across heterogeneous objects | Visitor |
| 问题场景 | 适用模式 |
|---|---|
| 需要解耦对象创建逻辑 | Factory Method、Abstract Factory |
| 包含多个可选字段的复杂对象 | Builder |
| 对象创建成本高,需要复制实例 | Prototype |
| 全局共享资源(配置、池) | Singleton |
| 第三方接口不兼容 | Adapter |
| 存在多个变化维度 | Bridge |
| 树形结构(文件、UI、组织结构图) | Composite |
| 无需子类化即可添加功能 | Decorator |
| 简化复杂API接口 | Facade |
| 大量相似对象,内存占用过高 | Flyweight |
| 懒加载、访问控制、缓存 | Proxy |
| 灵活的请求处理管道 | Chain of Responsibility |
| 撤销/重做、任务队列、宏操作 | Command |
| 自定义集合遍历逻辑 | Iterator |
| 对象间多对多通信 | Mediator |
| 快照、保存/恢复状态 | Memento |
| 事件系统、响应式更新 | Observer |
| 对象行为依赖于其状态 | State |
| 可替换算法(排序、压缩等) | Strategy |
| 算法步骤固定,但部分步骤可变 | Template Method |
| 异构对象间的操作 | Visitor |
| Principle | Summary | Related Patterns |
|---|---|---|
| Single Responsibility | One class, one reason to change | Strategy, Command, Observer |
| Open/Closed | Open for extension, closed for modification | Decorator, Strategy, Template Method |
| Liskov Substitution | Subtypes must be substitutable for base types | Factory Method, Abstract Factory |
| Interface Segregation | Prefer small, focused interfaces | Adapter, Facade |
| Dependency Inversion | Depend on abstractions, not concretions | All patterns using interfaces/abstract |
| 原则 | 总结 | 相关模式 |
|---|---|---|
| Single Responsibility | 一个类,一个变更理由 | Strategy、Command、Observer |
| Open/Closed | 对扩展开放,对修改关闭 | Decorator、Strategy、Template Method |
| Liskov Substitution | 子类必须能替换基类 | Factory Method、Abstract Factory |
| Interface Segregation | 优先使用小而专注的接口 | Adapter、Facade |
| Dependency Inversion | 依赖抽象,而非具体实现 | 所有使用接口/抽象类的模式 |