知识卡片
传输模型不复用内部对象
公开的输入输出对象与内部领域对象、数据库模型即使字段相同,也应审慎分开。直接复用内部对象会让表结构或实现变化越过服务边界,给消费者带来非预期兼容成本;映射层的维护是换取独立演进的代价。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第2章《Anti-Patterns: Lack of Isolation》(源文件:`_epub-src/OPS/ch02.xhtml`,归一化正文 [50347:54591))
- 结论依据:原文以 ProfileService 的 UserInput/UserOutput 为例,明确说若把内部用户对象直接复用为契约,就会耦合内部实现与显式契约。
- 原始内容:Looking at the contract, it is very likely we would have a table called Users in the implementation, as well as a user POJO in our core domain. So why not return that same class in our contract and re-use the code? Well, if we do, we would be coupling the internal implementation with the explicit contract. We do not want to do this if we want to have stable contracts.