I am developing a WPF application in which it will reference a class library that contains mostly business objects and some methods to manipulate those objects. Since this library is being used in conjunction with WPF, I have the need to use the INotifyPropertyChanged interface.
However, I do see future uses in the library which may not specifically rely on WPF (or posses the need for property change notifications) as the presentation layer. In your professional experience, would it be better to omit the interface to ensure the DLL is "clean" from unnecessary code for future uses by finding an alternative method, or use the interface and 开发者_如何学JAVAmove on?
(obviously, this could be applied to a variety of other programming practices).
Thanks.
I don't agree that INotifyPropertyChanged behavior is only to reside within the ViewModel. While INotifyPropertyChanged is heavily used within the Presentation layer, it's value extends beyond the Presentation layer.
Every one of my Models generally contains INotifyPropertyChanged behavior, not solely the ViewModel.
What this boils down to is if you can convince yourself that the INotifyPropertyChanged behavior may be used external to the Presentation layer by a consumer, leave it in.
I would omit the INotifyPropertyChanged in a business layer.
If I need to, I can derive children and make them INotifyPropertyChanged, or I can make a "model" class and it can contain an instance to my business objects.
This also helps to separate my business layers from my other layers (presentation, data access, etc.) as well as allowing me to use said objects in my server code which does not need to know anything about INotifyPropertyChanged.
INotifyPropertyChanged implementations belong with ViewModels, which encapsulate the state of the GUI/View and related behavior so that they are easily testable. ViewModels belong in the Presentation layer. All view-agnostic reusable code needs to be pushed down to another layer. So if you need to swap out WPF, build a different presentation layer, which uses this layer and you're good to go. A lower layer should not make assumptions of the layer above it.. so no INotifyPropertyChanged in this layer.
精彩评论