Search code examples
c#winformsmvp

How many presenters do I need in the MVP pattern


I'm trying to understand MVP pattern in c# winforms.
My question is do I have to create presenter class for each entity? For, example: In my Application I have:

  • Form1, in that form Students will list on a Listbox
  • Form2, in that form Orders will list on a Listbox
  • Form3, in that form Details will list on a Listbox

So in my Presenter application do I have to create?:

StudentPresenter.cs
OrderPresenter.cs
DetailsPresenter.cs

If yes, suppose I have a button in my Form1, when I click that button I want to show Form2. Is my code below true?

    private void showForm2_Click(object sender, EventArgs e)
    {
        var orderForm= new Form2();
        var orderRepo= new OrderRepository();
        var orderPresenter = new OrderPresenter(orderForm, orderRepo);
        //How I show Form2 ?
    }

Solution

  • Usually, what I have seen so far using the MVP-Pattern was to use One Presenter per View, in other words, it doesn't matter how many Models you have, the amount is decoupled from the amount of presenters. Also, in the project I worked previously, before switching to MVVM, the One-Presenter-Per-View was adhered to rigorously.

    This question has been asked several times here, in one form or another.

    See here or here.