简体   繁体   English

在软件体系结构中应在哪里实现INotifyPropertyChanged接口?

[英]Where to implement INotifyPropertyChanged interface in software architecture?

I am at the moment creating a project large enough in my opinion to separate carefully the well-known layers in its architecture. 我目前正在创建一个项目,该项目的规模足以将其体系结构中的知名层仔细分离。

For the data access layer (DAL), I simply use the .NET Entity Framework. 对于数据访问层(DAL),我仅使用.NET实体框架。

For the business layer, I defined business objects which are then available to subsequent developers who can use them to create clients and handle the UI. 对于业务层,我定义了业务对象,随后的开发人员可以使用这些业务对象,他们可以使用它们创建客户端并处理UI。

As I have to develop a client application as well for demonstration purpose, I realized that it can be very helpful to have an ObservableCollection<T> instead of a list, and that as often as possible the objects should implement the INotifyPropertyChanged interface so that the UI automatically detects the changes and displays the updates straightaway. 由于我还必须开发一个客户端应用程序以进行演示,因此我意识到使用ObservableCollection<T>而不是列表可能会非常有帮助,并且对象应尽可能多地实现INotifyPropertyChanged接口,以便UI自动检测更改并立即显示更新。

Yet, I wonder whether it is really the right way to do from a architectural point of view. 但是,我想知道从架构的角度来看这是否真的是正确的方法。 That is, technically , I don't think the business layer should have anything to do with UI display as we do not really "know" what a programmer might use it for; 也就是说,从技术上讲 ,我认为业务层不应该与UI显示有关,因为我们并不真正“知道”程序员可能将其用于什么; he might just want to use the objects for computational purposes for example. 例如,他可能只想将这些对象用于计算目的。 Hence, I was wondering what was the common practice? 因此,我想知道什么是惯例?

Should I implement these features in the business layer (there would be no performance issue)? 我应该在业务层中实现这些功能吗(不会有性能问题)? Should I create some kind of "decorator" object in another layer which includes all these features? 我是否应该在包含所有这些功能的另一层中创建某种“装饰器”对象?

As mentioned by Skliwz in the comments, the correct place to place this is in objects that are specifically bound to the UI layer. 正如Skliwz在评论中提到的那样 ,正确的放置位置是在专门绑定到UI层的对象中。

If you are binding your business objects directly to the UI layer, and you find that the INotifyPropertyChanged interface doesn't really belong on your business objects, then it's a clear indicator that you should have different objects for different purposes 如果您将业务对象直接绑定到UI层,并且发现INotifyPropertyChanged接口实际上并不属于您的业务对象,那么这清楚地表明您应该出于不同目的使用不同的对象

For example, you might want to have a view model, using the Model View View Model pattern. 例如,您可能希望使用“ 模型视图”视图模型模式创建视图模型

However, if you find that your business objects are to be monitored by other systems, and you need notifications as to when they changed, then the INotifyPropertyChanged interface is appropriate. 但是,如果发现您的业务对象将由其他系统监视,并且需要通知它们何时更改,则INotifyPropertyChanged接口是合适的。 However, it sounds like in your specific case, it is not. 但是,在您的特定情况下,听起来并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM