Search code examples
c#mvvmarchitectureinotifypropertychangeddomain-object

Does anything speak against making all domain objects inherit from INotifyPropertyChanged?


I'm refactoring and redesigning the domain objects of my application which uses MVVM to some extent. Is there anything that speaks against making all Domain objects (POCOs) inherit from INotifyPropertyChanged, so anyone can observe the objects as they wish.

In combination with https://stackoverflow.com/a/1316566/448357 this does not even have to be very ugly.

On the other hand, what about polluting my domain object with stuff that might not be required at all, because there will be a separate View-Model anyway? Margabit points out: UI Model != Domain Model


Solution

  • IMO, Domain objects shouldn't implement INotifyPropertyChanged. The one who should be implementing it is your ViewModel.

    The reasons for that is:

    1. You would probably mostly need to raise a PropertyChanged event inside your viewmodel which holds your POCOs
    2. You would be implementing it only once.
    3. If your POCO wants to raise an event and notify that something has occured inside it, im not sure PropertyChanged would be the most meaningful event to raise.