开发者

Webforms MVP: What is presenters responsibility

开发者 https://www.devze.com 2022-12-18 07:07 出处:网络
Am I wrong in my view that a pr开发者_StackOverflowesenter 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

Am I wrong in my view that a pr开发者_StackOverflowesenter 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号