Question

I have studied examples of MVP. None of the examples I found has a complex Form. In real life a form can get very complicated (specially if the client you are working for does not understand the "single responsibility principle").

Keeping this in mind, does the following example conforms to MVP principle?

Form Code - The form implements two interfaces, one for each presenter.

    public partial class ExampleForm : Form, ILookupView, IExampleView
    {
        //Constructor
        public ExampleForm()
        {
           InitializeComponent();

            var presenterEquipment = new EquipmentPresenter(this);
            presenterEquipment.PopulateEquipmentLookup();

            var presenterMain = new ManageComponentsPresenter(this);
            presenterMain.SetInitialValues();
        }
    }

If not what is the best way to handle large and complex forms?

Many Thanks.

Was it helpful?

Solution

I would split the view into smaller views, implemented as user controls and compose the large view of the small ones.

However, technically, I don't see any reasons why your approach wouldn't work. You can have your large view implementing several interfaces and assign multiple presenters to different "subviews".

OTHER TIPS

It has been my philosophy to make the design patterns match the needs of your app. Also My understanding of MVP, MVC is constantly growing. To answer your question though The relationship between the models of MVP are.

One View has One Presenter which talks to zero or more Models. The likely situation if you have a need for multiple Presenters for one view then those views are probably good candidates to be separated out into smaller subviews that are imported by a larger view. Or that there is business logic that can be separated out to one or more models

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top