views:

505

answers:

2

Am I wrong in my view that a presenter in the MVP design pattern should be lean and not have much logic just like the controller in MVC, and that most logic having to do with model updates should live in a application service.

My view is that presenter should just build up a command and send it to a service that would process it.

+1  A: 

That's basically the point of MVP, yes. I will add that MVC is typically considered a better alternative for web apps due to their stateless nature.

statichippo
Although you can do whatever you want in the presenter, moving you're whole application layer into your presenters would be an antipattern.
statichippo
A: 

I would keep it lean. You'll often find that if you load the presenters with business logic, you'll end up duplicating code. As soon as you find yourself doing this, move it down a layer into the business logic.

I tend to keep business operations on entities outside of the presenter as a rule of thumb.

e.g.

void view_Credit(object sender, EventArgs e)
{
    this.accountService.Credit(this.view.AccountId, this.view.AmountOfCredit);
}

rather than:

void view_Save(object sender, EventArgs e)
{
    Account a = this.accountService.GetByAccountId(this.view.AccountId);
    a.Balance += this.view.AmountOfCredit;
    a.DateUpdated = DateTime.Now;
    // lots of other business logic before you can save...
    this.accountService.Save(a);
}

I'm also not a big fan of passing entities through to the view, but that maybe is just a personal choice.

Junto
I don't think it is just personal choice, with using ViewModel, you can change the shape of your domain without having to change UI.
epitka