views:

51

answers:

2

Hi All,

You do you manage the same presenter working with different repositories using the MVP pattern?

I just have multiple constructor overloads and the presenter simply uses the one that is suitable for the scenario.

AddCustomerPresenter presenter = new AddCustomerPresenter(this,customerRepository); 
presenter.AddCustomer(); 

presenter = new AddCustomerPresenter(this,archiveRepository); 
presenter.Archive();
+1  A: 

Why not have

IRepository { /* .. */ }
CustomerRepository : IRepository { /* .. */ }
ArchiveRepository : IRepository { /* .. */ }

and then

AddCustomerPresenter {
IRepository Store {get;set;}
public AddCustomerPresenter(IRepository store) { /*...*/ }
/*...*/
}

Your presenter should NOT have any static dependency on ANY implementation of IRepository. If you find there's no other way, you need to rework your design because it's probably flawed.

Will
A: 

Thanks Will!

But CustomerRepository and ArchiveRepository are not related in any way. They are two completely different things.

azamsharp