Reputation: 29227
I am add some features to a complex form in legacy application. It already has a huge form with a lot of controls and tabs and a huge code behind cs file. I am trying to avoid to create a huge View/Presenter. Is it a good practice to add a view (and a presenter) for each feature of the form? Is there any better solution? I cannot separate the form into multiple forms because of users' requirement.
The form definition will look like this,
public partial class frmMyForm
: IView1, IView2, IView3, IView4, IView5,
IView6, IView7, IView8, IView9, IView10
{
....
Each IViewN
is different feature - for example, one is for visual data changing comparing, one is for display the data in the grids, one for summary statistics...
Why this post is being down voted? Comment your reason. Please don't down vote the question if you don't know what MVP is.
Upvotes: 2
Views: 2707
Reputation: 35869
There's nothing that says that there is a one-to-one-to-one relationship between a form, a view, and a presenter. In fact, it's a perfectly reasonable thing to do to break of the parts of a form into multiple "views" (I see this most often with User Controls; but it doesn't have to be that way) and have a presenter per view. It's most common that the Form is the view; but again, that's not mandatory.
As you say, this means avoiding some monstrous all-see\all-doing Presenter which should lead to more cohesive code and reduce unit-testing headaches.
Upvotes: 3
Reputation: 11727
If I understand it correctly, you are working in a legacy application and on an existing screen. And here, you need to add some new features. If that is the case, then adding there must be model, presenter and view available for this screen already. If that is the case, you have no other option but continue with the same architecture evn if your new features make the View and Presenter huge.
But if I am wrong and you are implementing the screen yourself, then you can introduce user controls with their own model, presenter and view. But make sure your user controls are independent of each other else it will again be a problem and confusion to create a bridge between user controls to communicate between them.
But honestly, I will prefer to create a single presenter and view for this task even if the files go huge. Generally user controls are used to create common controls that can be used in multiple places. With your approach, you may go for a toss if there is lot of communication between the user controls that you are creating. But yes, that can be eased out if the user controls are created with a great plan. But for me, having a single presenter and view is preferred unless they are in tightly coupled situation. And huge files should not be a problem when you have helping hand of plugins like resharper.
Upvotes: 1