original article: https://xiang753017.gitbook.io/zixiang-blog/patterns/patterns-for-organizing-domain-logic
Design Pattern 通常需要具備幾個描述要件 Context, Problem, Solution。
Domain Logic 在維護上管理上,需要精準的處理 Business model 需要兼顧軟體的維護性、可理解性、效能以及可測試性。當隨著軟體迭代,維護性、可理解性、效能以及可測試性都會隨著時間越來越複雜。
從[1] 文獻中,主要有三個 pattern 使用 Transaction Script, Table Moudle, Domain Model,隨著產品的生命週期,可以採用以順序為: Transaction Script -> Table Moudle -> Domain Model 。
Def: Organizes business logic by procedures where each procedure handles a single request from the presentation
Def: An object model of the domain that incorporates both behavior and data
在 Domain Model 需要盡可能對應需求的操作
def: A single instance that handles the business logic for all rows in a database table or view.
Pattern | Positive | Negative | Suggestion Scenario |
---|---|---|---|
Transaction Scripts | 1. 在實體小的feature 是容易理解的 2.學習難度低 | 擴充性很差,當要持續維護的時候難度很高,且會有很多重複的程式碼 | 一次性的 scripts |
Domain Model | 1.貼近 Business Logic 2.具備好的擴充性 | 1. 相對於三個patterns中最複雜的 2.學習曲線難度高 | 長期大型專案 |
Table Module | 1.具備好的擴充性 2. 學習難度低 | 1. 複雜度介於中間 2. Object 無法完全貼近真實情境 | 中長期大型專案 |
[1] Fowler, Martin. Patterns of enterprise application architecture. Addison-Wesley, 2012.