问题描述
我有两个事件类,称他们为 StatusChanged
和的ValueChanged
。我想了解一下这些公开流为的IObservable
。正在实施的IObservable<状态>
和的IObservable<价值>
在同一类坏?它是容易造成我(或类的用户)的悲伤?
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?
推荐答案
实现对不同类型的协变界面是一个真正的馊主意。试想,如果你投的类的IObservable<发生了什么;对象>
,也就是现在的暧昧
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.
我想而有两个属性的IObservable<状态> StatusObservable {获得{...}}
和的IObservable< VALUE> ValueObservable {获得{...}}
。简单,干净,它反映你的类提供了两个事件。
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.
这篇关于一个类实现两个不同的IObservables?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!