MVVM 和命名约定

发布于 2024-12-01 05:10:19 字数 611 浏览 0 评论 0原文

更新:感谢您结束我的问题,因为它可能会征求意见或讨论。这就是下面的免责声明所阐明的要点。有人可以重新打开这个吗?

免责声明:
首先,我意识到这个问题和可能的答案并不是非常黑白分明,但我陷入了僵局,我需要一些不同的观点。

问题:
当我在 WPF 中工作时,我经常使用 MVVM 模式来实现事情。在任何给定的程序中,我都会有一堆视图模型类,它们全部派生自名为“ViewModelBase”的类,我习惯在类名后缀“ViewModel”但是我发现我最终得到了很多名称很长的类,例如...

InputDataViewModel
CalculationsViewModel

等。我喜欢它们的名字中有一些上下文,但是当涉及到通用编程等时,它们可能有点麻烦。我开始认为它们都派生自“ViewModelBase”这一事实足以提供足够的信息将它们标识为视图模型,因此名称上的后缀变得比其价值更麻烦。

还有其他人对这个问题有类似的经验或见解吗?优点、缺点等?

另外:
不,我没有使用 MVVM 框架,如 calibburn、MVVMLight 或类似的框架。

Update: Thanks for closing my question because it might solicit opinions or discussion. That was the point as spelled out by the disclaimer below. Will someone please reopen this?

Disclaimer:
For starters, I realize how this question and possible answer isn't very black and white, but I am at an impasse and I need some different points of view.

Question:
When I am working in WPF, I often use the MVVM pattern to make things happen. In any given program I will have a bunch of View Model classes that all derive from a class called 'ViewModelBase' and it has been my habit to suffix the class names with 'ViewModel' However I am finding that I wind up with a lot of classes that have very long names such as...

InputDataViewModel
CalculationsViewModel

and so on. I like that they have some context in their name, but they can be a bit cumbersome when it comes to generic programming, etc. I am beginning to come to the opinion that the fact that they all derive from 'ViewModelBase' is enough information to identify them as view models and so the suffix on the names is becoming more trouble than it's worth.

Does anyone else have a similar experience or insight to offer on this issue? Pros, cons, etc?

Also:
No, I am not using an MVVM framework like caliburn, MVVMLight or anything like that.

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

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

发布评论

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

评论(1

若能看破又如何 2024-12-08 05:10:19

假设您使用的是一个好的 IDE,例如 Visual Studio,您确实不需要添加 ViewModel。这是因为 Visual Studio 的智能感知可以轻松查看类派生自什么、它支持的方法等。添加后缀的好处是,不使用高级 IDE 的人仍然能够使用您的代码。

此外,您可能还有其他涉及计算的类。为每个类名添加唯一的后缀可以让您或其他开发人员快速扫描代码时变得更加容易。如果没有后缀,可能需要在另一个文件中进一步查找才能确定类的作用。

Assuming that you are using a good IDE, like Visual Studio, you really don't need to add ViewModel. This is because Visual Studio's intellisense makes it easy to see what a class derives from, the methods it supports, etc. The benefit of adding the suffix is that people who don't use a fancy IDE will still be able to work with your code.

Also, you might have other classes that involve Calculations. Adding a unique suffix to each class name makes it easier when you or another developer is quickly scanning over your code. Without the suffix, it may require a further lookup in another file to determine what a class does.

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