Inheritance from a single base class that implements INotifyPropertyChanged

I use the following bit of code in cookie cutter mode, across dozens of classes

public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } 

All of these classes implement INotifyPropertyChanged . To disable my DRY alarms, lately I have refactored these classes to inherit my base class PropertyNotifier , whose sole purpose is to provide NotifyPropertyChanged for the classes inherited from it - there are dozens of ViewModel classes in my huge project.

He feels lazy and a little dirty. Can I harm work or disrupt good design practices? I believe that if the change notification should have been so simple, there would have been a base class already in the WPF environment, which does what my PropertyNotifier class does.

Please note that for many reasons I had performance issues with my user interface in mind - mainly due to the large number of controls. Therefore, I am looking to trim fat wherever I can. Any ideas?

+6
c # wpf mvvm inotifypropertychanged
source share
3 answers

This is a very common base class for developing WPF or Silverlight and will not significantly affect performance. The only problem I encountered with PropertyNotifier as a base class is that it is limited to one inheritance, but this is usually a rare problem with the type of class you will need.

+5
source share

Yes, this is a very common practice. For a large-scale application, you must have such a base class. We also created BaseViewModel for the same purpose; we also implemented a lot of common code (via ViewModels) in this base class, such as logging, displaying error messages, initializing WCF proxies, etc.

+3
source share

Another implementation is the WPF Application Framework (WAF) Model class. It does the same.

+2
source share

All Articles