Design by Contract:我们可以用合约来表达Stack FILO的属性吗?
合同设计似乎受到明示规格的限制。例如,我尝试用契约来表达 Stack FILO 属性,但没有得到任何想法。有人可以帮忙吗?
我认为根本原因是前置条件/后置条件/不变式是没有副作用的断言。这导致了FILO属性的检查,这是一种不容易甚至不可能的副作用。
It seems that design by contract has limit to express specification. For example, i tried to express Stack FILO property with contract, but didn't get an idea. Anybody can help?
I think the root cause is that precondition/postcondition/invariant are assertations without side effects. It leads to the checking of FILO property which is a kind of side effects not easy even possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确实如此,按合同设计的功能有限。它们不是灵丹妙药。因为如果是的话,IT 行业就会抛弃单元测试、代码审查等。
我建议您为这种情况编写简单的单元测试,而不是通过实现合同(甚至可能无法实现)来绞尽脑汁。
That's true, design by contract has limited functionality. They are not panacea. Because if they were then the IT industry would throw out unit-testing, code reviews etc.
I suggest you to write simple unit-test for this case rather than crack your head by implementing a contract (which even may be unimplementable).