views:

113

answers:

2

Hi,

In reading about the Observer design pattern, I noticed that it is implemented using interfaces. In Java, the java.util.observable implementation is also a class. Shouldn't the C# and Java versions use interfaces ?

Scott

+1  A: 

But they DO use interfaces. The ObservableCollection in .NET is an implementation of the interfaces - you are free to ignore it and to your own implementation.

TomTom
+4  A: 

Well, it implements INotifyCollectionChanged and INotifyPropertyChanged. However, interestingly, it doesn't implement the new IObservable<T> interface from .NET 4.0, which you might have expected.

It would arguably be useful for there to be a generic form of INotifyCollectionChanged... but I don't know of one.

Jon Skeet
So, I actually tried this, and it ends up being really ugly if you do it directly since any class that implements both IObservable<T> and IEnumerable<T> get *both* Rx and Linq extensions - lots of casting and gnashing of teeth. However, you could implement AsObservable() as an Extension Method pretty easily
Paul Betts