可重用类库 - INotifyPropertyChanged

发布于 2024-10-06 05:53:24 字数 285 浏览 4 评论 0原文

我正在开发一个 WPF 应用程序,其中它将引用一个类库,该类库主要包含业务对象和一些操作这些对象的方法。由于该库与 WPF 结合使用,因此我需要使用 INotifyPropertyChanged 接口。

但是,我确实看到该库的未来用途可能不会专门依赖 WPF(或需要属性更改通知)作为表示层。根据您的专业经验,最好是通过寻找替代方法来省略接口以确保 DLL 中的不必要代码“干净”以供将来使用,还是使用接口并继续前进?

(显然) ,这可以应用于各种其他编程实践)。

谢谢。

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 move on?

(obviously, this could be applied to a variety of other programming practices).

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一曲爱恨情仇 2024-10-13 05:53:24

我不同意 INotifyPropertyChanged 行为仅驻留在 ViewModel 中。虽然 INotifyPropertyChanged 在表示层中大量使用,但它的价值超出了表示层。

我的每个模型通常都包含 INotifyPropertyChanged 行为,而不仅仅是 ViewModel。

归根结底,如果您能够说服自己 INotifyPropertyChanged 行为可以由消费者在表示层外部使用,请将其保留。

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.

落墨 2024-10-13 05:53:24

我会省略业务层中的 INotifyPropertyChanged。

如果需要,我可以派生子级并使它们成为 INotifyPropertyChanged,或者我可以创建一个“模型”类,它可以包含我的业务对象的实例。

这也有助于将我的业务层与其他层(表示、数据访问等)分开,并允许我在服务器代码中使用所述对象,而无需了解有关 INotifyPropertyChanged 的​​任何信息。

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.

护你周全 2024-10-13 05:53:24

INotifyPropertyChanged 实现属于 ViewModel,它封装了 GUI/View 的状态和相关行为,以便易于测试。 ViewModel 属于表示层。所有与视图无关的可重用代码都需要下推到另一层。因此,如果您需要换出 WPF,请构建一个使用该层的不同表示层,然后就可以开始了。较低层不应对其上方层做出假设。因此,该层中没有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文