返回主题:契约式设计

知识卡片

普通读书笔记卡 · 1971.o.1.b.1.a.1.d.1.b

断言明确状态契约

理解等级:中级

名称能提示操作意图,却未必说清会改变什么。断言把状态契约写明:前置条件说明保证成立所需的输入/状态;后置条件说明操作完成后的保证;类或聚合不变量说明每次操作结束都应保持的完整性规则。它们描述状态而非内部执行步骤,且上层操作的保证应涵盖下层委托产生的效果。若语言不直接支持,可用测试建立前置条件、执行操作并检查后置条件,同时在适当的文档或图中保留契约。参见[[接口名称表达领域意图]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第10章|Assertions · 查看原书依据

      Briefly, "post-conditions" describe the side effects of an operation, the guaranteed outcome of calling a method. "Preconditions" are like the fine print on the contract, the conditions that must be satisfied in order for the post-condition guarantee to hold. Class invariants make assertions about the state of an object at the end of any operation. Invariants can also be declared for entire AGGREGATES, rigorously defining integrity rules.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第75章《Assertions》(源文件:_epub-src/0321125215_ch10lev1sec3.html;单元01) - 结论依据:原文分别定义前置、后置和类/聚合不变量,说明它们以状态而非过程描述操作结果;并建议在语言缺少直接支持时用自动化测试和文档表达。 - 原始内容:Briefly, "post-conditions" describe the side effects of an operation, the guaranteed outcome of calling a method. "Preconditions" are like the fine print on the contract, the conditions that must be satisfied in order for the post-condition guarantee to hold. Class invariants make assertions about the state of an object at the end of any operation. Invariants can also be declared for entire AGGREGATES, rigorously defining integrity rules.