This question is really about covariance and contravariance of generic types. We have
an IViewA
is an IView
but that does not automatically mean that
an IPresenter<IViewA>
is an IPresenter<IView>
When the conclusion holds, we say that IPresenter<T>
is covariant in T
. In C# one makes an interface covariant by putting an out
keyword before the type parameter in question (here T
), as in:
interface IPresenter<out T> ...
Since you didn't put the out
keyword, what you do is not allowed.
But it is only safe to make a type covariant in T
if all the uses of T
goes "out". For example it is okay to use T
as return type of methods or as property type for get
-only properties.
Your interface uses T
in an "in" position, namely as a value parameter (i.e. a parameter without the ref
(or out
) modifier). So it would be illegal to make your interface covariant. See some of the other answers for examples of what could happen if this restriction wasn't there.
Then there's the notion of contravariance, which for IPresenter<>
means that
an IViewA
is an IView
implies that
an IPresenter<IView>
is an IPresenter<IViewA>
Notice how the order changes with contravariance. Contravariance is only safe (and only allowed) when the type parameter is used in "in" positions, such as value parameters.
Based on the only member, it would be legat to declare your interface contravariant:
interface IPresenter<in T> ...
where in
means contravariant, of course. But it will reverse the "direction" in which implicit conversions are allowed.