![](/img/trans.png)
[英]Eiffel: a way to call precursor redefined feature on another function
[英]Eiffel: void safety, a concise way to test if an object exists and then call its feature
我想知道是否有更清晰的陈述
if not attached foo then
create foo
end
if attached foo as l_foo then
l_foo.bark
end
如
if not attached foo then
create foo
foo.bark
else
foo.bark
end
会重复foo.bark
,显然我想避免它...甚至最后一条语句也不会使用void-safety进行编译,因为其他的foo可能是无效的...
为了避免代码重复和多次测试,可以使用以下代码:
l_foo := foo
if not attached l_foo then
create l_foo
foo := l_foo
end
l_foo.bark
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.