ObservableObject : IDisposable

Jul 18, 2009 at 1:53 AM

Great stuff Josh. Just whats MVVMers needed.

Why is the IDisposable interface not implemented in the ObservableObject abstract class. Is it more efficient to implement it in a derived class,  Or is there another reason?

Thanks. Dan

Jul 18, 2009 at 3:02 AM

An ObservableObject has nothing to dispose of, so there's no way, in my mind, to justify having it implement IDisposable.



Jul 18, 2009 at 5:28 AM

Thanks Josh.

The ViewModelBase class from your MVVM MSDN article uses the IDisposable but i see now that its probably to dispose the DisplayName string property. Thanks. Another stupid question from your great MSDN article/project.

If your were to build that project again using these new classes what would you do differently ?

Jul 18, 2009 at 5:33 AM

ViewModelBase in my MSDN Magazine article implemented IDisposable because I needed a standard place for ViewModel objects to unhook events of other objects before they were released, and thus made eligible for garbage collection.  That was application-specific, and in a general purpose library, such an arbitrary interface implementation does not make sense (to me).

If I were to build that project again, I think I'd use Messenger to alert the AllCustomersViewModel that a new customer was added to the repository, instead of hooking a CustomerAdded event.  In fact, had I done that, there wouldn't have been a need to implement IDisposable on the ViewModelBase because then I wouldn't have needed to unhook that event when the AllCustomersView was closed.

Jul 18, 2009 at 5:56 AM
Edited Jul 18, 2009 at 6:04 AM

Thanks Again

I feel dumb :)  I see the purpose of IDisposable now. Thanks. I need to dig into this Messenger and PropertyObserver class. I just cant keep up with all your great contributions.

Feel free to delete this Discussion. Your library does not need discussion contributions from me:)

Jul 18, 2009 at 6:02 AM

No worries!  I am not going to delete this discussion, I think it has value.  It made me rethink the design of my MSDN demo app.  Thanks for your feedback.  :)