I understand that, if S
is a child class of T
, then a List<S>
is not a child of List<T>
. Fine. But interfaces have a different paradigm: if Foo
implements IFoo
, then why is a List<Foo>
not (an example of) a List<IFoo>
?
As there can be no actual class IFoo
, does this mean that I would always have to cast each element of the list when exposing a List<IFoo>
? Or is this simply bad design and I have to define my own collection class ListOfIFoos
to be able to work with them? Neither seem reasonable to me...
What would be the best way of exposing such a list, given that I am trying to program to interfaces? I am currently tending towards actually storing my List<Foo>
internally as a List<IFoo>
.