0

What is the proper way of precising the type of an iterable through inheritence.

as inherit FOO[like babar] is not alowed

FOO

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

BAR

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

enter image description here

Pipo
  • 4,653
  • 38
  • 47

1 Answers1

1

I would suggest using a formal generic parameter in class FOO:

class FOO [G]
inherit
    ITERABLE [G]

Then, class BAR would provide a suitable actual generic parameter:

class BAR
inherit
    FOO [STRING]
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • I was thinking too about this solution, but don't want to give for each l_foo: FOO[detachable ANY] but maybe the only way is to 'FOO_GENERIC_ANY inherit FOO[detachable ANY]' :( – Pipo Jun 12 '20 at 19:39
  • 1
    @Pipo As far as I know, anchored types are not going to be supported in parent clauses soon, so I do not see a better solution at the moment. – Alexander Kogtenkov Jun 12 '20 at 19:47