Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INotifyPropertyChanged usage outside data binding

I've never used INotifyPropertyChanged, and I'm considering using it widely throughout a new application.

My question is, is it 'proper' to use INotifyPropertyChanged interface in order to provide event notifications for things other than databound controls?

It seems from a bunch of examples online that this interface is widely used for notifying grids and such for when data is changed. I have various scenario's where I need other classes to be notified of data changes in other classes, and I was wondering if you think it's cleaner to implement this interface, and perform the changed call on setters, or rather just create regular events.

like image 279
mservidio Avatar asked Sep 08 '11 12:09

mservidio


1 Answers

When making a choice like this, I lean towards using language features over other constructs.

A severe downside to INotifyPropertyChanged is that it only provides the property name as a string on update, and your consuming classes have to parse that string and decide how to act on it.

With events you can provide any kind of delegate signature that the event requires and the consuming classes can act on that change directly.

If you peek under the hood, you'll find that INotifyPropertyChanged is an event anyway, so why not use events directly?

like image 119
Ritch Melton Avatar answered Sep 25 '22 02:09

Ritch Melton