The Acyclic Dependencies Principle (ADP)
Allow no cycles in the component dependency graph.
元素依賴關係中不允許出現環。
Example
Solution
- 利用依賴反轉原則。
Summary
- 隔離易變性。
- 提高可建置性 (buildability) 和可維護性 (maintainability)。
The Stable Dependencies Principle (SDP)
Depend in the direction of stability.
朝著穩定的方向抽象。
Definition
- Fan-in: 輸入依賴度。元件外部,依賴於該元件的類別個數。
- Fan-out: 輸出依賴度。元件內部,依賴於元件外的類別個數。
- Instability: 不穩定性。
I=Fan−out(Fan−in+Fan−out),I∈[0,1]
Example
計算I值
違反SDP的例子
Solution
利用依賴反轉原則。
Summary
The Stable Abstractions Principle (SAP)
A component should be as abstract as it is stable.
元件的抽象程度應該與穩定程度一致。
- 一個穩定的元件應該是抽象的。
- 一個不穩定的元件應該是具體的。
- 依賴應該朝著抽象的方向。
Definition
- Nc 一元件中類別中的總數。
- Na 一元件中抽象類別及界面的總數。
- A 表示抽象性。A=Na÷Nc 。 A∈[0,1]。
Example
Summary
藉由定義出計算抽象性的度量方式,
我們便可以監控依賴關係在不同版本間的變化,
進而對設計作出調整。
ʕ •ᴥ•ʔ:順手整理一下以前寫過的筆記。
Gitalking ...