Bad design to implement both. You have two different child objects that you subscribe to two observers. I recommend having two children, each of which implements one of the interfaces.
class Beholder { public IObserver<Foo> FooObserver{get;private set;} public IObserver<Bar> BarObserver{get;private set;} }
When is the controversy ambiguous?
However, I do not see an immediate problem here, so the VB.net warning looks really strange to me.
IObserver<in T> is contravariant. Therefore, to cause ambiguity, you need to find T , such as IObserver<Foo> and IObserver<Bar> are IObserver<T> .
If both Foo and Bar are independent classes, such a T does not exist, since it must be deduced from both of them, which does not allow a system of type .net.
If each of them were an interface, there would be ambiguity: just create a class that derives from Foo and implements IBar .
If it was obtained from another, it would also be ambiguous: if Foo obtained from Bar , then IObserver<Bar> also IObserver<Foo> .
When is the combination ambiguous?
And finally, with co-variant interfaces such as IEnumerable<T> , itβs enough to have a common base class, for which both are reference quotes. And Object does this for any two classes (but not for value types).
But IEnumerable<T> will break even without covariance, because you need a consistent implementation of non-generic IEnumerable , and this is not possible for two independent classes.
CodesInChaos Dec 27 '11 at 18:29 2011-12-27 18:29
source share