What is Model View Presenter?

37,969

Solution 1

Martin Fowler has a page on UI design patterns, in which he defines and then talks about MVC, MVP and other patterns.

http://martinfowler.com/eaaDev/uiArchs.html

To summarise the differences, Controllers in the MVC have more control over the UI, and handle events, while a presenter in the MVP is more passive, and just presents information through the UI.

In general there's not much difference, and often the line between them is blurry.

Solution 2

Model View Presenter and Model View Controller both try to solve the same "seperation of concerns" problem.

The primary difference you'll find is that Model View Controller (MVC) is often implemented with some coupling between the view and some model of some sort - thereby a given view is specifically purposed to provide a visualization of a given object (model).

In the Model View Presenter pattern you generally find that the Presenter takes care of working with the model, and deciding what information from it will be needed to form some sort of visualization.

In this diagram, arrows represent dependencies:

MVC and MVP dependencies

Typically you hear this pattern discussion come up when discussing the ASP.NET MVC framework, and come across information regarding the MVP pattern and it's implementation in ASP.NET WebForms. It is common in my experience that it is believed that WebForms is in and of itself an MVP patterned framework - this is not true. WebForms does however make it very easy to implement an MVP pattern - your best resource for this would be to investigate the Web Client Software Factory from the Patterns and Practices team.

Solution 3

Fowler separates MVP into 2 patterns: Supervising Presenter and Passive View.
Aviad Ezra has a good article on this topic http://aviadezra.blogspot.com/2008/10/model-view-presenter-design-pattern.html.
I think MVP is better for desktop, and MVC is for web app, because in desktop, Model has the capability to raise the event

Solution 4

Dolphin Smalltalk used to have an MVC implementation but then they migrated to MVP.

Here's the technical paper that outlines what they did and why.

IBM's Taligent system also used MVP - they describe what and why here.

Share:
37,969
bluediapente
Author by

bluediapente

Updated on July 08, 2022

Comments

  • bluediapente
    bluediapente almost 2 years

    Can someone please explain in a way as simple as possible what the Model View Presenter pattern is? What is the difference with Model View Controller ? Which is best or for which purpose ?

  • Noon Silk
    Noon Silk over 14 years
    In either case, you're involved with models, and that's got to be a good thing.
  • Cameron MacFarland
    Cameron MacFarland over 14 years
    I'm not sure those dependency arrows are right. In MVC, why does the View have a dependency on the Model?
  • Shawn Benson
    Shawn Benson over 14 years
    It certainly doesn't have to be, however this is the more common implementation. For example, if you use ASP.NET MVC the best practice is to make your "view" dependent on a type (creating a strongly typed view). Typical MVC implementations send a model to a view, then let the view decide what to do with it (thereby creating a dependency), whereas in MVP the View will literally ask the presenter "What data should I put in this textbox."
  • Xonatron
    Xonatron over 12 years
    TwistingTheTriad.PDF link no longer works.
  • Dafydd Rees
    Dafydd Rees over 12 years
    Have fixed the "Twisting the Triad" URL.
  • Coops
    Coops about 11 years
    @daf I was really interested to read but TwistingTheTriad.PDF goes to a blank page currently =(
  • DavidRR
    DavidRR almost 10 years
    I found the referenced article by Aviad Ezra to be quite helpful for getting me started using the MVP architectural pattern with my WinForms desktop application. The included example code is easy to understand.
  • hakan
    hakan about 8 years
    You can raise events using ajax calls or websockets. It is about server-side actually.