关于 WinForms 应用程序的 MVC 模式的建议

发布于 2024-10-20 23:20:32 字数 438 浏览 3 评论 0原文

我正在编写 Mac 应用程序的 Windows 版本(C# Winforms),并且希望获得一些有关使用哪种设计模式的建议。

我的 Mac 应用程序使用 MVC 模式和 Core Data 进行存储。这是模型和关系的简化图:

模型图

桌面应用程序在后台线程上收集日志并定期上传它们到我的网络应用程序。该数据库用于存储用户的帐户信息和日志,并且该应用程序有 3 个视图来显示(和收集)用户的数据。

我已经阅读了一些内容,似乎 MVP 是 WinForms 应用程序的推荐设计模式,但我不确定如何从这里继续。我认为我的应用程序足够简单,无需使用 MVC# 等外部框架即可编写,但由于我之前从未制作过 WinForms 应用程序,所以我只是猜测。

有人可以推荐解决这个问题的最佳方法吗?

I'm writing a Windows version of my Mac app (C# Winforms) and would like some advice on what design pattern to use.

My Mac app uses an MVC pattern with Core Data for storage. This is a simplified diagram of the models and relationships:

model diagram

The desktop app collects logs on a background thread and periodically uploads them to my web app. The database is used to store both the user's account information and logs, and the app has a 3 views to display (and collect) the user's data.

I've done some reading and it seems that MVP is the recommended design pattern for WinForms apps, but I'm not sure how to proceed from here. I think that my app is simple enough to write without using an external framework like MVC# but as I have never made a WinForms app before I am only speculating.

Can someone recommend the best way to go about this?

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

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

发布评论

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

评论(4

隐诗 2024-10-27 23:20:32

模式实际上只是关于它试图解决什么问题的指南。 MVC 对于依赖页面和重定向等的 Web 应用程序来说效果很好,而 winform 应用程序可以从使用 MVP 中受益。

话虽如此,这两种模式是更广泛的 UI 模式的兄弟,甚至根据 Martin Fowler 的说法,MVP 模式可以进一步拆分。请参阅他的文章,以更好地了解适当的模式。他将 MVP 打破为监督控制者和被动视角。甚至新的 MPF MVVM 模式实际上也是基于PresentationModel 模式。

我会说查看模式并看看什么适合,而不是尝试使用模式,因为您在另一个场景中使用了它。

Patterns are really just guides as to what problem it is trying to solve. Where an MVC would work well for a web app that relies on pages and redirects etc a winform app can benefit from using MVP.

Having said that the two patterns are siblings of a wider UI pattern and even according to Martin Fowler the MVP pattern can be further split. Look at his article to get a good feel for the appropriate pattern. He has broken the MVP to Supervising Controller and Passive View. Even the new MPF MVVM pattern is actually based on the PresentationModel pattern.

I would say look at the patterns and see what fits rather than trying to use a pattern because you used it in another scenario.

野鹿林 2024-10-27 23:20:32

根据我对 winforms 应用程序(支持良好的数据绑定)的经验,您可以将 MVC 与监督控制器模式一起使用。仔细阅读这个问题 什么是 MVP 和 MVC?有什么区别? & http ://codebetter.com/jeremymiller/2007/05/25/build-you-own-cab-part-3-the-supervising-controller-pattern/

In my experience for a winforms application (which supports nice databinding) you can use MVC with a supervising controller pattern. Read through this question What are MVP and MVC and what is the difference? & http://codebetter.com/jeremymiller/2007/05/25/build-you-own-cab-part-3-the-supervising-controller-pattern/

﹏雨一样淡蓝的深情 2024-10-27 23:20:32

您应该看看 Jeremy Miller 的“打造您自己的出租车”系列:
http:// codebetter.com/jeremymiller/2007/07/26/the-build-your-own-cab-series-table-of-contents/

You should take a look at Jeremy Miller's Build your own cab series :
http://codebetter.com/jeremymiller/2007/07/26/the-build-your-own-cab-series-table-of-contents/

一向肩并 2024-10-27 23:20:32

开始研究它,做一些屏幕模型,做一些设计,编写一些代码。

你可以从一些小原型开始,尝试不同的设计。在你的探索阶段不要走得太远,这样你就可以毫不犹豫地把它扔掉并在需要时重新开始。

尽量保持你的选择开放,不要把自己逼到墙角,并推迟这个决定,直到你真的需要选择一种方式而不是另一种方式。

到那时,您可能会对自己的需求有更好的了解。

Start to work on it, do some screen mockups, do some design, write some code.

You could start with a few small prototype, try out different design. Don't go too far in your exploration phase so that you don't hesitate to throw it away and start over if you need.

Try to keep your choice open as much as possible, don't paint yourself into a corner, and delay this decision until your really need to choose one way over another.

By then you will probably have a much better Idea of what you need.

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