views:

714

answers:

3

IObservable<T> and IObserver<T> interfaces are placed directly in the System namespace in .NET Framework 4.0 Beta2. Why not in System.Collections.Generic, like IEnumerable<T>?

p.s. Reactive Framework preview from Silverlight Toolkit contains IObserver<T> in the System.Collections.Generic namespace.

+4  A: 

IObservable is an interface that identifies a class that implements the Observer pattern. Its not related to Collections. Its more related to providing an alternative to Events.

Andrew Keith
IObservable<T> is a dualism for IEnumerable<T>, it's not only related to events, collections may be observable too :) It's just push-based IEnumerable<T> at first look. ReactiveFramework in the Silverlight Toolkit contains IObservable<T> and IObserver<T> interfaces at System.Collections.Generic namespace as I expect, but not in .NET 4.0
ControlFlow
You're not making any sense, ControlFlow. Of course collections may be observable. But the fact that a collection may be observable doesn't mean that anything observable is a collection. There are plenty of generic interfaces and types in the CLI that aren't in System.Collections.Generic.
Kyralessa
@ControlFlow: IObservable<T>/IObserver<T> have nothing to do with collections specifically. Sure, a collection could be observable, but so can non-collections. Observation is a lower-level thing than collections, intended to support the **observer** pattern in a more decoupled, less language-specific way (i.e. alternative to C# events). It is most definitely *not* a dualism for IEnumerable<T>.
jrista
@ControlFlow: The System.Collections.Generic namespace is for *System* defined *Collections* that are *Generic*. IObservable is system-defined, and it is generic, but it isn't a collection; An instance of a class implementing IObservable is a single thing, not a group of things.
Skirwan
+2  A: 

The thing that new IObservable/IObserver interfaces describe is an abstraction much higher than just collections which can be seen as a special case of computations (that's why lists in Haskell are monads). So it's obvious that such generalization is placed to System namespace.

Take a look at this brilliant cast from Erik Meijer where he describes the ideas behind the interfaces.

UserControl
+1  A: 

Although this is an old question I stumbled upon, I just wanted to back @ControlFlow's assessment of the 'dualism' between IObservable and IEnumerable as a 'Pushed based' vs 'Pull based' collection with a link to Erik Meijer's 'Rx in 15 Minutes', where he can be quoted as saying exactly that. http://channel9.msdn.com/posts/Charles/Erik-Meijer-Rx-in-15-Minutes/

Consequently, this pushed-based collection can fundamentally shift the basic paradigm of 'a mundane series of called events' into an asynchronous, selectable, query-able, passable and subscribe-able first-class collection of declarative actionable. Something that does that belongs in the core BCL namespace or perhaps deserves it's own, but is too far beyond Yet-Another-Collection to share its namespace. Mind you, that's just my opinion.

Andre White