使用MVC,MVP或MVVM模式为WinForms编写的向导?

时间:2021-04-23 05:51:17

All of the WinForms wizards I've written in the past have a high degree of coupling between the UI and the model. That is: the individual pages know about enabling/disabling the Next/Previous buttons, how to react to the Next button being pressed, etc. It makes it all hard to test, because to test any of the logic, you've got to put a lot of scaffolding together first.

我过去编写的所有WinForms向导在UI和模型之间都有很高的耦合度。那就是:各个页面都知道启用/禁用下一个/上一个按钮,如何对按下的下一个按钮做出反应等等。这使得测试很难,因为要测试任何逻辑,你必须先把很多脚手架放在一起。

I've been using MVC (in the form of ASP.MVC) recently, and I'm finding that easy to test. I've also had a play with WPF, and I think I'm getting my head around M-V-VM.

我最近一直在使用MVC(以ASP.MVC的形式),我发现它很容易测试。我也玩过WPF,我想我已经开始了解M-V-VM。

I'm struggling with the M-V-P pattern in WinForms (i.e. no WPF-style databinding). In particular, I need to implement a wizard.

我正在努力使用WinForms中的M-V-P模式(即没有WPF风格的数据绑定)。特别是,我需要实现一个向导。

Would I have a controller per page? A view model that governs the whole wizard? Something else?

我每页都有一个控制器吗?一个管理整个向导的视图模型?别的什么?

This is in WinForms (not WPF), in C#. .Net 2.0 preferred.

这是在WinForms(不是WPF)中,在C#中。 .Net 2.0首选。

2 个解决方案

#1


In the end I opted for something between MVVM and MVP, using a mixture of WinForms databinding and view callback interfaces. I guess it's closer to MVP than MVVM. Each page has a viewmodel/presenter, and the wizard itself has its own viewmodel/presenter to govern flow (certain options skip later wizard pages, for example).

最后,我选择了MVVM和MVP之间的东西,使用WinForms数据绑定和视图回调接口的混合。我猜它比MVVM更接近MVP。每个页面都有一个viewmodel / presenter,向导本身有自己的viewmodel / presenter来管理流程(例如,某些选项会跳过以后的向导页面)。

It turned out pretty well, and it fairly easy to write unit tests for each of the presenter classes.

结果非常好,并且为每个演示者类编写单元测试相当容易。

The underlying wizard framework doesn't use MVVM or MVP. It's just plain ol' WinForms code.

底层向导框架不使用MVVM或MVP。它只是简单的'WinForms代码。

#2


Have a look at the Smart Client Software Factory.

看看智能客户端软件工厂。

#1


In the end I opted for something between MVVM and MVP, using a mixture of WinForms databinding and view callback interfaces. I guess it's closer to MVP than MVVM. Each page has a viewmodel/presenter, and the wizard itself has its own viewmodel/presenter to govern flow (certain options skip later wizard pages, for example).

最后,我选择了MVVM和MVP之间的东西,使用WinForms数据绑定和视图回调接口的混合。我猜它比MVVM更接近MVP。每个页面都有一个viewmodel / presenter,向导本身有自己的viewmodel / presenter来管理流程(例如,某些选项会跳过以后的向导页面)。

It turned out pretty well, and it fairly easy to write unit tests for each of the presenter classes.

结果非常好,并且为每个演示者类编写单元测试相当容易。

The underlying wizard framework doesn't use MVVM or MVP. It's just plain ol' WinForms code.

底层向导框架不使用MVVM或MVP。它只是简单的'WinForms代码。

#2


Have a look at the Smart Client Software Factory.

看看智能客户端软件工厂。