MVVM 和命名约定
更新:感谢您结束我的问题,因为它可能会征求意见或讨论。这就是下面的免责声明所阐明的要点。有人可以重新打开这个吗?
免责声明:
首先,我意识到这个问题和可能的答案并不是非常黑白分明,但我陷入了僵局,我需要一些不同的观点。
问题:
当我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用的是一个好的 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.