We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
类之间差异很大,启发式方法很难获得。不过,对于特定风格的课程,会有很多启发式的方法。例如,每个设计模式实现都有自己的一组不变量。
获得不变量的最好、最简单的方法是从类应该做什么的规范开始[或者如果进行 TDD,则进行测试测试],并找出要正确实现这些规范必须满足哪些条件。换句话说,您“通过代码推动您的规范”。当您这样做时,不变量将“出现”为您遇到的绊脚石。
请注意,有时“推动”意味着前置条件的前向传播,有时意味着后置条件的向后传播。大多数情况下,两者都是。
classes vary so much from each other, heuristics will be hard to come by. There will be lots of heuristics for particular styles of classes though. For example, each design pattern implementation has its own set of invariants.
The best and simplest way to get your invariants is to start from a specification of what your class is supposed to do [or a test of tests if you do TDD], and figure out what conditions must be true for those specifications to be properly implemented. In other words, you "push your specifications through your code". As you do this, invariants will 'appear' as the stumbling blocks you encounter.
Note that sometimes "pushing through" means forward propagation of pre-conditions, sometimes it means backwards propagation of post-conditions. Most often, both.