开发者

Heuristics for finding class invariants [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

Improve this question

Is there any heuristics for finding class invariants, I mean

  • pay attantion on ...;
  • never rely on ...;

Maybe there is common advices.

Any开发者_StackOverflow links on paper where studing real-life examples will be welcome.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜