How many presenters should be used in Model View Presenter with Winforms with tabs?
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 navigat开发者_如何学运维e to the other tabs (based on category of data selected).
I create one presenter per view. If each tab is a separate view, then each tab would have it's own presenter.
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.
精彩评论