| 信号 | 超过一半方法是一行转发 |
|---|---|
| 手法 | Remove Middle Man、Inline Class |
| 对照 | 与 Hide Delegate 是相反方向的拉锯 |
内联方向
内联方向
// 之前
class Account {
double balance() { return this.ledger.balance(); }
}
// 之后:调用方直接持有 ledger(依赖方向清晰时)类的大部分方法只是转发给另一个对象:用 Remove Middle Man、Inline Class 削减多余委托;封装与转发之间要找平衡点,而不是谁转发谁就坏。
| 信号 | 超过一半方法是一行转发 |
|---|---|
| 手法 | Remove Middle Man、Inline Class |
| 对照 | 与 Hide Delegate 是相反方向的拉锯 |
// 之前
class Account {
double balance() { return this.ledger.balance(); }
}
// 之后:调用方直接持有 ledger(依赖方向清晰时)