| 信号 | 改一个字段要动十几个文件 |
|---|---|
| 手法 | Move Function、Move Field、Combine Functions into Class |
| 反向对照 | 发散式变化(Divergent Change):一个类因多种原因被改 |
聚拢思路
聚拢思路
// 分散:多处各自计算有效期
// 聚拢:一个模块负责「有效期」概念
class Validity {
boolean isValid(Instant now) { ... }
}一个变化需要同时改很多处(分散在各处的相似修改)时,用 Move Function、Move Field、Inline Class 把相关代码聚拢;目标是单一修改点。
| 信号 | 改一个字段要动十几个文件 |
|---|---|
| 手法 | Move Function、Move Field、Combine Functions into Class |
| 反向对照 | 发散式变化(Divergent Change):一个类因多种原因被改 |
// 分散:多处各自计算有效期
// 聚拢:一个模块负责「有效期」概念
class Validity {
boolean isValid(Instant now) { ... }
}