Search code examples
c#.netpoco

Implementing INotifyPropertyChanged on a POCO


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


Solution

  • 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.