知识卡片
重复代码要按变化性质取舍
业务规则与合规处理重复会让修复分散,宜集中在服务;少量配置、样板代码或即将退役组件的代码,局部重复却可能隔离迁移风险。是否复用应按长期变化与所有权成本判断,不能只数重复行数。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第4章《Anti-Patterns: Internal Shared Libraries》(源文件:`_epub-src/OPS/ch04.xhtml`,归一化正文 [71185:75430))
- 结论依据:原文分别讨论业务与合规代码的坏重复,以及迁移中复制少量库代码以缩小影响范围的好重复。
- 原始内容:Duplicated code is isolated. Duplicating code can be used as a tool to reduce the blast radius of an API. Imagine you have 3 different services using the same internal shared library. If you want to decommission the library, you need to migrate the 3 projects to a new solution. But, what if one service will also be decommissioned shortly, in 6 months? Migrating all 3 projects sounds like waste, and it is.