带选项卡的Winforms在Model View Presenter中应使用多少个主持人? [英] How many presenters should be used in Model View Presenter with Winforms with tabs?

查看:73
本文介绍了带选项卡的Winforms在Model View Presenter中应使用多少个主持人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有与业务实体相关的标签的表单-例如一个人具有个人履历数据,地址数据等.每个选项卡都处理一个人数据类别的输入/编辑,并且每个选项卡都可以独立保存.是否应在所有选项卡中使用一个演示者,或在每个选项卡中使用一个演示者?可能还有一个主选项卡,可以导航到其他选项卡(基于所选数据的类别).

I have a form with tabs related to a business entity - e.g. a Person has biographical data, address data, etc. Each tab handles input/editing of a category of Person data, and each tab can be saved independently. Should one presenter be used for all tabs, or one presenter per tab? There may also be a main tab, which can navigate to the other tabs (based on category of data selected).

推荐答案

在我看来,这里发生的合乎逻辑的事情是,您正在处理单个人的数据.对于演示者来说,UI(即视图)是使用标签页,电子表格还是统一的条目控件列表,都是偶然的.

In my opinion the logical thing happening here is that you are working with the data of a single person. It is incidental to the presenter whether the UI i.e. view is using tabs, a spreadsheet, or a unified list of entry controls.

视图应负责在选项卡之间切换,从演示者发送数据以及将演示者提供给它的数据放置在正确的位置.

The view should have the responsibility of of switching between tabs, sending data from the presenter, and placing the data the presenter gives it in the correct places.

演示者获取视图发送的数据,并执行所需的任何验证并将其存储.当接收到新数据时,它还负责更新视图.

The presenter takes the data the view sends it and does whatever validation is needed and stores it. It is also responsible for updated the view when new data received.

这样,如果选项卡界面不起作用,则可以通过让新的UI实现视图界面来轻松切换.

This way if the tab interface doesn't work then it is easy to switch by having the new UI implement the view interface.

如果仅更新一个选项卡很重要,则可以使用类别的概念来设计演示者.作为演示者逻辑的一部分,它告诉视图仅更新一类数据.

If it is important to updates only one tab then the presenter can be design with the concepts of categories. As part of the logic of the presenter it tell the view to update only one category of data.

在统一输入表单上,这将仅显示为表单更新的一部分.在您原始帖子中提到的选项卡式表单上,这将导致一个选项卡更新.

On a unified entry form this will manifest as only one section of the form updating. On the tabbed form that you mentioned in your original post, this will result in one tab updating.

在类的数量及其功能之间取得平衡非常重要.很少有人会做很多事情,这些事情在将来的维护中将很难分开.太多了,它们之间的关系将变得混乱,这又使将来的维护变得复杂.

It is important to strike a balance between the number of classes and their functionality. To few and they are doing to many things that will be hard to separate in the future maintenance. Too many and it will become confusing as to their relationship again complicating future maintenance.

这篇关于带选项卡的Winforms在Model View Presenter中应使用多少个主持人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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