How many presenters should be used in Model View Presenter with Winforms with tabs?

女生的网名这么多〃 提交于 2019-12-22 08:54:47

问题


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).


回答1:


I create one presenter per view. If each tab is a separate view, then each tab would have it's own presenter.




回答2:


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.

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.



来源:https://stackoverflow.com/questions/4700592/how-many-presenters-should-be-used-in-model-view-presenter-with-winforms-with-ta

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!