Design Pattern 設計模式 - paulip114/blog GitHub Wiki

What is design pattern?

Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can customize to solve a particular design problem in your code. 設計模式是軟體設計中常見問題的典型解決方案。每個模式就像一個藍圖,您可以自訂它來解決程式碼中的特定設計問題。

Why? Benefit?

Patterns are a toolkit of solutions to common problems in software design. They define a common language that helps your team communicate more efficiently. 模式是解決常見 軟體設計上的問題。他們定義 一種可以幫助您的團隊的通用語言 更有效地溝通。

Three major class of design patterns:

Creational patterns 建立型模式, Structural patterns 結構型模式, Behavioral patterns 行爲型模式

1. Creational patterns:

  • 提供物件 Object 的建立機制,提高程式碼的靈活性和重用性
    • Factory Method 工廠方式
    • Abstract Factory 抽象工廠
    • Builder 生成
    • Prototype 原型
    • Singleton 單例

2. Structural patterns:

  • 將物件 Object 和類別 Class 組裝成更大的結構,同時保持靈活性和高效
    • Adapter 轉接器
    • Bridge 橋接
    • Composite 組合
    • Decorator 裝飾
    • Facade 外觀
    • Flyweight 輕量
    • Proxy 代理

3. Behavioral patterns:

  • 著重於物件 Object 之間的交流行爲,增加程式碼的彈性
    • Chain of Responsibility 責任鏈
    • Command 命令
    • Memento 備忘錄
    • Observer 觀察者
    • Template Method 模板方法
    • Visitor 訪問者
    • Iterator 迭代器

Reference: https://refactoring.guru/design-patterns