架构的WinForms应用程序? [英] Architecture for WinForms applications?

查看:172
本文介绍了架构的WinForms应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始了一个WinForms项目在几个星期前,当我真的不知道有什么特点,我想,我只是说他们前进的道路。现在,这造成了可怕的混乱在我的MainForm的是泥和那里的大球比如一些国家重要的变化是由UI元素我必须调用控件的OnChange事件,以改变数据库中的某些状态的时间点触发

I have started a WinForms project a few weeks ago and as I did not really know what features I wanted, I just added them along the way. This now caused a horrible mess where my MainForm is a big ball of mud and where for example some important state changes are triggered by UI elements to the point I have to call the OnChange Event of a Control in order to change some state in the database.

总之:我刚开始一个新的项目,我想采取一个更好的方法。我只是不知道这将是好之一。在ASP.net MVC,我发现MVVM模式真的很有用,但在桌面上,MVVM似乎只适用于WPF,而不是WinForms的。

In short: I've just started a new project where I want to take a better approach. I just don't know which would be the "good" one. In ASP.net MVC, I found the MVVM Pattern really useful, but on the Desktop, MVVM seems to be only intended for WPF, not for WinForms.

另一种方法是一个三层架构:我有我的数据库级目前直接交谈UI。我现在创建一个新的静态类(ApplicationState),讨论到数据库并触发事件告诉UI嘿,东西变了!。用户界面将操纵国然后将处理数据库持久性和再次提高活动如果UI需要更新。这里的一点是,ApplicationState类不能直接修改的UI,但该UI订阅活动。这的看起来的喜欢做的清洁/MVC-Y的方式,但也许我在这里可以俯瞰什么?

The other approach is a three-tier-architecture: I have my Database-Class which currently talks directly to the UI. I now create a new Static Class ("ApplicationState") that talks to the database and fires events to tell the UI "Hey, Something changed!". The UI would manipulate the State which will then handle the database persistence and again raise Events if the UI needs updating. The point here is that the ApplicationState class never modifies the UI directly, but that the UI subscribes to Events. That looks like a clean/"MVC-y" way of doing it, but maybe I am overlooking something here?

基本上我的最终目标是将有完全独立于数据库层的UI只是为了确保我不会在业务逻辑线到UI一次。

Basically my ultimate goal would be to have the UI completely independent from the database layer just to make sure I don't wire in business logic into the UI again.

推荐答案

不要在MVVM认输 - 这是有效的WinForms为好。基本上,如果你使用数据绑定,你必须做出一个关于你的对象将绑定到决定。通常情况下,尤其是对于更复杂的UI,你不想直接绑定到你的域对象,要建立专门的类(有时包装),你的UI可以绑定到其提供的一切观点需要(MVVM的本质)和技术作品同样出色的WinForms。

Don't throw in the towel on MVVM - it's valid for WinForms as well. Basically, if you use data-binding, you have to make a decision about what your objects will bind to. Often, especially for more complex UI, you dont want to bind directly to your domain objects, you want to build specialized classes (sometimes wrappers) that your UI can bind to which provide everything the view needs (the essence of MVVM) and the technique works just as well with Winforms.

上的WinForms模型 - 视图 - presenter一个好的方法系列可以在

A good series on WinForms Model-View-Presenter approach can be found at

<一个href=\"http://$c$cbetter.com/blogs/jeremy.miller/archive/2007/07/25/the-build-your-own-cab-series-table-of-contents.aspx\"相对=nofollow>构建内容你自己的CAB系列表

这篇关于架构的WinForms应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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