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?
Asked
Active
Viewed 193 times
2
Benjol
- 63,995
- 54
- 186
- 268
-
1Have you tried anything yet? – MrFox Jan 28 '13 at 10:57
-
@MrFox, nope. I simplified the situation for the sake of the question. This is an API from a supplier, which is not yet cast in concrete, I could yet ask for this, but I don't want to if it's a bad idea. – Benjol Jan 28 '13 at 11:07
1 Answers
5
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.
CodesInChaos
- 106,488
- 23
- 218
- 262