开发者

3-promise rule for functions

I need help remembering what book I read this from, It might have been Effective开发者_Go百科 C++ or something, but I don't remember. I was reading something that basically stated that functions have 3 promises:

  1. Validate input parameters to make sure they meet the expected input requirements
  2. Guaranteed to respect & maintain invariants
  3. Validate output parameters (returns & out params)

The book also had some nice names for this but for the life of me I don't remember. It bothered me enough that I had to come to Stackoverflow to see if someone might recognize this and help me remember...


The name of the concept is 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜