C# MVC 模式帮助

发布于 2024-10-14 07:52:33 字数 200 浏览 2 评论 0原文

我正在尝试将我的 Winforms 代码重构为 MVC 模式。我以前从未使用过这种模式。

显然,GUI 将是视图,控制器将是由用户与 GUI 的任何交互调用的“中间层”,模型执行所需的任务并通知视图任何状态更改。

我的问题是,对于模型,我假设它可以跨越大量的类,并且不限于一个“模型”类?另外,这三个部分可以都在同一个程序集中吗?

谢谢。

I am having a go at refactoring my Winforms code into MVC pattern. I have never used this pattern before.

Obviously the GUI will be the view, the controller will be the 'middle tier' which is invoked by any user interaction with the GUI, and the model performs the requried tasks and informs the view of any status changes.

My question is, with the model, I am assuming that can span a great number of classes and is not confined to one 'model' class? Also, can these three sections all be within the same assembly?

Thanks.

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

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

发布评论

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

评论(6

ㄟ。诗瑗 2024-10-21 07:52:33

对于 Winforms,我不建议 MVC - id 建议 MVVM

尝试本教程 http://weblogs.asp.net/dwahlin/archive/2010/09/30/silverlight-sessions-coming-to-devconnections-las-vegas- november-1-4.aspx

本文提到了 Silverlight,但 MVVM 模式是通用的,可以应用于 Winforms,

正如 Roger Lipscombe 指出的那样 - MVP 也可能有效 - 尝试此以获取有关 http://davybrion.com/blog/2010/08/mvp-in-silverlightwpf -architectural-overview/ - 再次特定于 Silverlight,但作为一种模式,它可以进行调整

for Winforms i wouldnt suggest MVC - id suggest MVVM

try this tutorial http://weblogs.asp.net/dwahlin/archive/2010/09/30/silverlight-sessions-coming-to-devconnections-las-vegas-november-1-4.aspx

this article mentions Silverlight but the MVVM pattern is generic and can be applied to Winforms

as pointed out by Roger Lipscombe - MVP may also work - try this for information on that http://davybrion.com/blog/2010/08/mvp-in-silverlightwpf-architectural-overview/ - again specific to Silverlight in this light but as its a pattern it can be adapted

沙与沫 2024-10-21 07:52:33

对于 Winforms,我建议学习 MVP(模型/视图/演示者)和 MVC 模式。虽然其他人建议 MVVM 可能是一个好主意,但我不同意 - MVVM 利用 WPF 中提供的数据绑定,尽管 Winforms 在某种程度上支持绑定,但它并不像 WPF 体系结构/对象模型那样以绑定为中心。

“模型”层可以由许多类组成,在对架构的这一层中的类进行建模时,我将始终使用“单一职责原则”以及其他 Solid 原则。

有用的链接:

For Winforms I would suggest learning about the MVP (Model/View/Presenter) and the MVC pattern. Although others have suggested MVVM might be a good idea I disagree - MVVM takes advantage of data binding offered in WPF and although Winforms supports binding to some extent, it's not as binding centric as the WPF architecture/object model.

The 'Model' layer can consist of many classes and I would always use the 'Single Responsibility Principle' as well as other Solid principles when modelling the classes within this layer of your architecture.

Useful links:

坏尐絯 2024-10-21 07:52:33

不,模型并不局限于某一模型类。在模型中,您通常表示数据库和其他与数据相关的内容。控制器负责大部分操作。

是的,所有这些组件都将落在一个 dll 中。肯定会有很多其他文件,例如视图文件,它们并不总是在 MVC 中编译(但您可以强制这样做)。

No, model is not confined to one model class. In model you usually represent your database, and other data-related stuff. Controllers are responsible for most of the actions.

And yes, all this component will land in one dll. Bet there will be a lot of other files, like view files, which are not always compiled in MVC (but you can force that).

猫九 2024-10-21 07:52:33

您可能想考虑将“模型”类创建为接口。然后,所有特定模型都实现该接口,但共享通用方法(例如更新、删除等),

它们绝对可以编写在同一个程序集中。您的文件夹结构(严格来说)应该遵循模型/视图/控制器结构,并将代码文件分别放置在这些结构下面。

You might want to think about making a 'Model' class as an interface. Then all of your specific models implement that interface but share common methods (such as update, delete, etc.)

They can definitely be written in the same assembly. Your folder structure (strictly), should follow a Models/Views/Controllers structure, and place the code files underneath those respectively.

飘然心甜 2024-10-21 07:52:33

如果您决定尝试 MVP 模式(这对于 Winforms 来说是一个不错的选择),请查看 MVC#,用于构建 MVP 应用程序的框架。这既简单又好。

If you decide to try out the MVP pattern, which is a good choice for Winforms, check out MVC#, a framework for building MVP applications. It's simple and good.

擦肩而过的背影 2024-10-21 07:52:33

也许您对我将 MVC/MVP 模式与具有流畅接口的数据绑定相结合的方法感兴趣。 mvc 和数据绑定,最好的方法是什么?

在我看来,是否使用 MVC、MVP 或 MVVM 是一个角度问题。它们都会导致数据的抽象、逻辑和数据的可视化。

Maybe you are interested in the approach I am heading for to combine the MVC/ MVP pattern with Databinding with fluent interfaces. mvc and databinding, what is the best approach?

If MVC, MVP or MVVM is used is from my point of view a matter of perspective. They will all lead to an abstraction of data, logic and visualization of the data.

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