Eiffel重定义函数可以定义自己的断言吗?
我需要知道 Eiffel 中重新定义的函数是否可以定义自己的断言。
I need to know if a redefined function in Eiffel can define its own assertions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以。但重新定义的功能只能削弱其父级的前提条件并加强其后置条件。为了更清楚地说明,您必须在重新定义的功能中将前置条件声明为
require else
,并将后置条件声明为ensure then
以明确您正在弱化/强化相应的断言。有关更深入的说明,请参阅文档网站。
Yes it can. But a redefined feature can only weaken its parent's precondition and strengthen its postcondition. To make it clearer you are forced to declare your precondition as a
require else
in the redefined feature, and declare the postcondition as anensure then
to make it clear that you are weakening/strengthening the corresponding assertion.See the documentation site for a more in depth explanation.