[英]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.