I was curious what was the best thing to do with ViewModels
. Is it better to implement the interface INotifyPropertyChanged
or to derive from ObservableObject
.
ObservableObject
class implements INotifyPropertyChanged
and do some of the boring code like RaisePropertyChanged
.
INotifyPropertyChanged
require to implement PropertyChanged
event.
From my point of view it seems more logical to use ObservableObject
, but in most of the tutorial they implement INotifyPropertyChanged
interface on their ViewModel
.
Do you think it's for the sake of simplicity or there's a logical reason ?
You should always have the Model implement INotifyPropertyChanged and this is just a mistake which would be corrected if this were developed from a code example to an application.
The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed.
The ObservableObject is a base class for objects that are observable by implementing the INotifyPropertyChanged and INotifyPropertyChanging interfaces. It can be used as a starting point for all kinds of objects that need to support property change notifications.
ObservableObject
is part of Microsoft.Practices.Composite.Presentation - i.e. Prism. It's also been implemented in MVVM Light and MVVM Foundation.
INotifyPropertyChanged
is part of System.ComponentModel - i.e. it's in the core libraries.
So, if you are not already including Prism or one of the other frameworks I'd stick with INotifyPropertyChanged
. There seems to be little point in including it just to get this one class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With