Is INotifyPropertyChanged View-Only?

It is a sign of INotifyPropertyChanged, obviously very useful in the presentation model of data binding to the presentation. Should I use this interface in other parts of my application (for example, at the business level) when I want to be notified of property changes, or am I better off using other notification mechanisms? I understand that nothing prevents me from using, but are there any reasons that I should not do?

+4
source share
2 answers

INotifyPropertyChanged not very explicit, and it is error prone, because you somehow need to specify a string with a property that has changed and will potentially become obsolete when you reorganize the specified property to a different name. If this is your class that consumes some kind of notification, I think it is more reasonable to talk about it in more detail and indicate what changes.

+1
source

INotifyPropertyChanged can be a little painful to implement, although there are tools that can make it cleaner and less error prone (for example, PostSharp can automate the setter notification plumbing, so you don’t need to code them manually (there are no more line references in the installer), but tools like Resharper can perform renames, which also update references to a string with a property name.)

I personally implement this interface in my Model layer, although it is not consumed almost the same way by other model objects. In most cases, Model objects usually do not listen on a single property change; rather, they observe a general change in state, which may include several properties. Such a change is better notified by a specific event. However, I pretty often use INotifyCollectionChanged, exposing collections of objects in the public ObservableCollection classes and responding to change events, rather than creating a bunch of wrapper methods to access the private collection and update status.

0
source

Source: https://habr.com/ru/post/1306909/


All Articles