通过继承确定可迭代类型的正确方法是什么?
因为不允许继承FOO [像babar]
class FOO
inherit
ITERABLE[detachable ANY] -- I know garbage but for DB_RESULT its the case
feature -- Access
new_cursor: ITERATION_CURSOR[like items.item]
do
Result := items.new_cursor
end
items: ARRAY[detachable ANY]
end -- class FOO
class BAR
inherit
FOO -- I know garbage but for DB_RESULT its the case
ITERABLE[STRING] -- I know garbage but for DB_RESULT its the case
feature -- Access
new_cursor: ITERATION_CURSOR[like items.item]
do
Result := items.new_cursor
end
items: ARRAY[STRING]
end -- class FOO
我建议在类FOO
中使用正式的泛型参数:
class FOO [G]
inherit
ITERABLE [G]
然后,类BAR
将提供合适的实际通用参数:
class BAR
inherit
FOO [STRING]