知识卡片
替换要保持行为契约
里氏替换要求实现被替换后仍满足调用者原有契约,不能突然增加前置条件或削弱承诺。原书Push实现用kwargs要求额外device_token,会让同一调用在换实现后失败;接口签名相同不能证明可替换,应在共同契约或适配层处理渠道差异。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Design for Speed and Efficiency · 查看原书依据
The Liskov Substitution Principle (LSP) states that objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. In a serverless context, this principle can be applied to the design of function interfaces and the interaction between different services.
参考来源
- 位置:《Building Distributed Systems Designing scalable architectures with microservices, event-driven patterns, and robust deployment…》第05章《Design for Speed and Efficiency》(来源项目book-sources;源文件:extracted/Building Distributed Systems Designing scalable architectures with microservices, event-driven patterns, and robust deployment…/_epub-src/OPS/ch05.xhtml)
- 结论依据:原文给出本卡对应定义或示例;里氏替换要求实现被替换后仍满足调用者原有契约,不能突然增加前置条件或削弱承诺。 对原文省略和过度承诺的限定是本卡显式纠正,不能反过来当作原书已证明。
- 原始内容:The Liskov Substitution Principle (LSP) states that objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. In a serverless context, this principle can be applied to the design of function interfaces and the interaction between different services.