Reputation: 907
I have a POCO class with a number of properties that can be get/set.
Does implementing INotifyPropertyChanged on this class violate the principles of a POCO?
I would like another class to be notified of any changes to the POCO and write these changes to a file, and having it listen for a property changed seems like the best way of doing this
Upvotes: 2
Views: 820
Reputation: 16409
As long as it fulfills your requirement AND you know what you are doing, there is no problem.
In software world, people generally face same problem redundantly. To handle these problems in consistent and tested/verified way, patterns/paradigms were introduced. All patterns/paradigms generally lay down the guidelines. Most of them (few does though) do not state how those should be implemented.
That said, it is up to the developer who is implementing the pattern decide the implementation details. Make sure you do not create new problem through your implementation.
Term POCO is derived from its Java equivalent POJO. Following is what Martin Fowler says about POJO:
In the talk we were pointing out the many benefits of encoding business logic into regular java objects rather than using Entity Beans. We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely.
Notice the bold text in above quote.
Considering this, implementing INotifyPropertyChanged
on POCO class should not be considered a violation the POCO principles.
About INotifyPropertyChanged
and MVVM relation: The interface is defined in System.ComponentModel
and is NOT tightly bound to MVVM.
Upvotes: 1
Reputation: 10883
You need one way or another to notify your application of changes in the database (provided there's more than one instance at a time).
Making your POCOs implement INotifyPropertyChanged
is a legimate way to do so. Note that it resides in the System.ComponentModel
namespace and - although used widely in WPF - is not a ui-thing.
An alternative could by some CQRS-scheme that notifies your POCO-consuming services of changes via specifically designed interfaces.
Upvotes: 1