gpt4 book ai didi

c++ - 函数的 3-promise 规则

转载 作者:太空狗 更新时间:2023-10-29 20:17:40 25 4
gpt4 key购买 nike

我需要帮助来记住我从哪本书中读到这本书,它可能是 Effective C++ 之类的,但我不记得了。我在读一些基本上说函数有 3 个 promise 的东西:

  1. 验证输入参数以确保它们满足预期的输入要求
  2. 保证尊重和维护不变量
  3. 验证输出参数(返回和输出参数)

这本书也有一些好听的名字,但我不记得了。这让我很困扰,以至于我不得不来 Stackoverflow 看看是否有人会认出这一点并帮助我记住......

最佳答案

概念的名称是Design by Contract :

  • Expect a certain condition to be guaranteed on entry by any client module that calls it: the routine's precondition—an obligation for the client, and a benefit for the supplier (the routine itself), as it frees it from having to handle cases outside of the precondition.
  • Guarantee a certain property on exit: the routine's postcondition—an obligation for the supplier, and obviously a benefit (the main benefit of calling the routine) for the client.
  • Maintain a certain property, assumed on entry and guaranteed on exit: the class invariant.

关于c++ - 函数的 3-promise 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6230269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com