IObservable<T> and INotifyPropertyChanged - is there a connection

AwkwardCoder picture AwkwardCoder · Jan 29, 2010 · Viewed 7.3k times · Source

I understand the IObservable<T> & IObserver<T> are implementations of the observer pattern and can be used in similar circumstances to .Net events.

I was wondering if there is any relationship to INotifyPropertyChanged?

I currently use INotifyPropertyChanged for data binding in winforms & WPF applications and was wondering if I'll be able to use IObservable in UI data binding scenarios?

Cheers

AWC

Answer

micahtan picture micahtan · Feb 9, 2010

From what I can gather, there is no relationship. Observers/.NET eventing are two ways of achieving the Observer/Notification style behavior.

Microsoft's answer has been to build on top of the .NET eventing pattern, not deprecate it in favor of manually registered Observer objects.

One of my biggest peeves with events is the inability to clear the delegate chain on demand, which leads to quite a few managed-memory leak scenarios. To this end, Microsoft introduced the concept of weak events, that is, to address the issue of mismatched timelines for Observables/Observers.

You can read more about the WeakEvent pattern here.

Josh Smith has released an implmentation of the WeakEventManager for INotifyPropertyChanged here. This provides a safer (from a memory-standpoint) way of hooking up objects which change properties, and their Observers.