知识卡片
跨语言契约避开专属类型
服务接口一旦跨网络给不同语言的客户端调用,不能直接把 Java BigDecimal 等语言专属类型当作共同契约。应选择各方都能解释的线格式,并明确数值精度等语义;转为“基础类型”并不自动保留精度。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第2章《Anti-Patterns: Lack of Isolation》(源文件:`_epub-src/OPS/ch02.xhtml`,归一化正文 [50347:54591))
- 结论依据:原文用 Java BigDecimal 接口转为 REST/JSON 或 gRPC 的例子指出跨语言互操作问题,并建议网络边界考虑更通用的类型;精度约束是据此补出的设计边界。
- 原始内容:How about your consumer services or UIs not written in Java? When we consider exposing the contract over the network, relying on primitive types might be a better idea from an interoperability point of view.