Where should View & Presenter appear

Now I fully understand the MVP pattern, but I'm still trying to see how views and presenters are created. I have seen some examples where a presenter appears in a view, but this is correct. After reading Jeremy Miller's blog post about communicating between View and Presenter, he had a feature in Presenter to attach a presenter to the view.

My question is: where should presentations and speakers be created? Also where in winforms and webforms.

+5
source share
3 answers

In web forms, the page receives an instance of the request. Since the page is a view, and you cannot control the execution order, this view must be registered with the presenter

+3
source

In Winforms, I instantiate the view as needed (for example: in a method mainor in a method of another host, but where it really makes sense). The view then creates and registers with a new instance of the presenter.

This leads to the fact that several views easily use the same presenter logic and protect the users of my view from my particular architecture for using MVP.

+2
source

-, . -, . - .

:

public class SomePresenter
{
    public ShowContactView(IContactView view)
    {
        IContact model = new Contact();
        new ContactPresenter(model, view);
        view.Show();
    }
} 

public class AnotherPresenter
{
    public ShowContactView(IContactView view)
    {
        IContact model = new Contact();
        new ContactPresenter(model, view);
        view.Show();
    }
} 

public class YetAnotherPresenter
{
    public ShowContactView(IContactView view)
    {
        IContact model = new Contact();
        new ContactPresenter(model, view);
        view.Show();
    }
} 

public partial class ContactView : Form, IContactView
{    
    public ContactView()
    {
        InitializeComponent();
    }
}

:

public class SomePresenter
{
    public ShowContactView(IContactView view)
    {
        view.Show();
    }
} 

public class AnotherPresenter
{
    public ShowContactView(IContactView view)
    {
        view.Show();
    }
} 

public class YetAnotherPresenter
{
    public ShowContactView(IContactView view)
    {
        view.Show();
    }
} 

public partial class ContactView : Form, IContactView
{    
    public ContactView()
    {
        InitializeComponent();

        new ContactPresenter(new Contact(), this);
    }
}

, . , , , , , .. , , .

, " " , Presenter View, Presenter . View Presenter..

But more importantly, to see how different models fit your business. To be honest, there are even more options. See this duplicate question.

+1
source

All Articles