问题
I have a class with two events, call them StatusChanged
and ValueChanged
. I'm wondering about exposing these 'streams' as IObservable
. Is implementing IObservable<Status>
and IObservable<Value>
on the same class 'bad'? Is it likely to cause me (or users of my class) grief?
回答1:
Implementing a covariant interface for different types is a really bad idea. Consider what happens if you cast the class to IObservable<object>
, which is now ambiguous.
I'd rather have two properties IObservable<Status> StatusObservable{get{...}}
and IObservable<Value> ValueObservable{get{...}}
. Simple, clean and it mirrors the two events your class offers.
来源:https://stackoverflow.com/questions/14560134/a-class-implementing-two-different-iobservables