0

Imagine a simple application with a list of customers:

CustomerWindow: ICustomerView
{
    private CustomerPresenter customerPresenter;

    CustomerWindow()
    {
        this.customerPresenter = new CustomerPresenter(this);
    }
}

When the user clicks on a particular customer, the customer data editor window is displayed:

EditorWindow: IEditorView
{
    private EditorPresenter editorPresenter;

    EditorWindow()
    {
        this.editorPresenter= new EditorPresenter(this, ???);
    }
}

EditorPresenter must know the customer chosen by the user, but view doesn't know anything about the customer model and other model-layer parameters necessary for properly initialization of EditorPresenter.

How can I solve this problem?

1 Answers1

0

You need to take a step back and re-think how you're implementing the MVP pattern. Each triad should be a discrete unit. Each presenter should depend on a view and a 'model'. You have it so that your views are dependent on the presenter. I don't think this is correct.

I would have it so that the EditorPresenter is instantiated with an instance of IEditorView and a Customer or CustomerRepository.

I have created a rudimentary MVP framework for Windows Forms (shapemvp.codeplex.com) that illustrates how I think MVP should be done based on a lot of reading around the subject. It's unfinished but has a basic sample app that demonstrates the kind of feature you're describing.

David Osborne
  • 6,436
  • 1
  • 21
  • 35