MVC实现与Windows窗体 [英] Implementing MVC with Windows Forms

查看:396
本文介绍了MVC实现与Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里可以找到如何完全实现MVC模式在Windows窗体一个很好的例子?

Where can I find a good example on how to completely implement the MVC pattern in Windows Forms?

我发现很多教程和code例子在各种网站(例如,的code计划和.NetHeaven),但许多人更重presentative比MVC观察员模式。因为我要开发的应用程序是一个学校项目,我不愿意使用框架喜欢的 PureMVC的 MVC#

I found many tutorials and code examples on various sites (for example, The Code Project and .NetHeaven), but many are more representative for the observer pattern than MVC. Since the application I want to develop is for a school project, I am reluctant to using frameworks like PureMVC or MVC#.

推荐答案

我的应用程序,相互借鉴,我们的应用程序应该如何还是非常有限的理解完全不同的观点。过去的Windows窗体应用程序我都在一直互不相让不同的工作。一些我所看到的是差异化的设计(包括大多数的组合):

I am of the view that applications are so different from each other and our understanding of how applications should be written is still very limited. Past Windows Forms applications I have worked on have been so different from each other. Some of the design differences I have seen are (including most combinations):

  • 直接与数据库(2层)
  • 使用已经写入了给定的应用后端(3层)
  • 使用一组被用于许多应用程序编写并不能为你的应用程序更改Web服务。 (面向服务的架构)
  • 在更新由 CRUD 操作完成
  • 更新正在做的命令格式(发送命令到后端服务器)
  • 在很多数据绑定用法/没有用途的数据绑定
  • 在大多数数据是表样(如发票),在标准网格工作以及控制/需要自定义控件的大部分UI数据。
  • 在一位开发商/ 10或20的开发者(只是在UI)小组
  • 在很多单元测试的用嘲笑等/没有单元测试
  • Directly talk to the database (2 tier)
  • Use a backend that has been written for the given application (3 tier)
  • Use a set of web services that were written for use by many applications and can’t be changed for your application. (Service-oriented architecture)
  • Updates being done by CRUD operations
  • Updates being done with the command pattern (sending commands to backend server)
  • Lots of usages of data binding / no usages of data binding
  • Most data being "table like" (e.g. invoices) that work well in standard grid controls / need custom controls for most of the UI data.
  • One developer / teams of 10 or 20 developers (just on the UI)
  • Lots of unit test using mocks etc / no unit tests

因此​​,我不认为它可以创建一个实现MVC(或MVP)总是非常适合的。

Therefore I don’t think it’s possible to create one implementation of MVC (or MVP) that always fits well.

我见过的最好的帖子真的解释 MVC和为什么的MVC系统是建立事情是这样的,是<一个href="http://$c$cbetter.com/blogs/jeremy.miller/archive/2007/07/25/the-build-your-own-cab-series-table-of-contents.aspx"相对=nofollow>建立自己的CAB系列由JeremyÐ米勒。虽然工作后​​,你应该能够理解你的选择好了很多。 微软的智能客户端指引(CAB /微软复合应用程序块)也应考虑。这是一个有点复杂,但它可以很好的工作有一个良好的配合应用。

The best posts I have seen really explaining MVC and why an MVC system is built the way it is, is the "Build Your Own CAB" series by Jeremy D Miller. After working though it you should be able to understand your options a lot better. Microsoft's Smart Client Guidance (CAB / Microsoft Composite Application Block) should also be considered. It is a bit complex, but it can work well for applications that have a good fit.

选择一个<一个href="http://rdn-consulting.com/blog/2008/02/01/selecting-a-mvcmvp-implementation-for-a-winforms-project/"相对=nofollow> MVC / MVP实施的WinForms项目给出一个概要,值得一读。很多人喜欢 PureMVC的。我从来没有使用过,但我会在接下来的时间,我需要一个MVC框架看看吧。

Selecting an MVC/MVP Implementation for a Winforms Project give an overview that is worth reading. A lot of people like PureMVC. I have never used it, but I would look at it the next time I need a MVC framework.

presenter首先是一种软件开发方法,结合了的模型 - 视图 - presenter想法(MVP)的设计模式和测试驱动开发 。它可以让你通过编写测试,在客户的语言开始。例如:

"Presenter First" is a software development approach that combines the ideas of the Model View Presenter (MVP) design pattern and test-driven development. It lets you start off by writing tests in the customer’s language. For example:

当我点击保存按钮,然后   该文件应该被保存,并且   未保存的文件警告应   消失了。

"When I click the 'save' button then the file should be saved and the unsaved file warning should disappear."

我用没有经验presenter首先,但我会试试看,当我得到一个机会,因为它看起来非常有前途的。

I have no experience using "Presenter First," but I will give it a try when I get a chance, as it looks very promising.

其他堆叠式和NBSP;溢出问题,你可能会想看看是这里和<一href="http://stackoverflow.com/questions/122388/how-would-you-implement-mvc-in-a-windowsforms-application">here.

Other Stack Overflow questions you may may wish to look at are here and here.

如果你正在考虑使用的 WPF 在任何时候看看的的模型 - 视图模型(MVVM)模式。这里是一个非常不错的视频,你应该看看:杰森Dolinger的模型 - 视图 - 视图模型

If you are thinking of using WPF at any point take a look at the Model-View ViewModel (MVVM) pattern. Here is a very good video you should take a look at: Jason Dolinger on Model-View-ViewModel.

MVVM(模型 - 视图 - 视图模型)设计模式的的WinForms 的给另一种选择,可能使在需要时它easer转换为WPF。 Magical.Trevor 是另一个MVVM样品Windows窗体,其中还包括自动捆绑基于属性名称

MVVM (Model View View Model) Design Pattern for Winforms give another option that may make it easer to convert to WPF if ever needed. Magical.Trevor is yet another MVVM sample for Windows Forms that also includes auto binding based on property names.

另外问一下自己的为什么您正在使用MVC。

Also ask yourself why you are using MVC.

  • 您是否希望能够单元测试高达code越好?
  • 您是否尝试让尽可能多的code,尽量重复使用?
  • 您是否想让您的code基易于理解?
  • 101其他原因,可以适用于特定的项目。

一旦你清楚你的目标,它变得更容易选择一个实现或其他。

Once you are clear on your aims, it becomes easier to choose one implementation or another.

这篇关于MVC实现与Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆