Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask

aspnet, aspnetmvc, code, patterns 0 comments suggest edit

Or, as my recent inbox tells me, you’re not afraid to ask. ;)

A coworker recently asked for some good resources on getting up to speed on the Model View Controller (MVC) pattern. Around the same time, I received another email talking about how people are confused around the difference between MVC and the Model View Presenter (MVP) pattern.

mvcNo better opportunity to apply the DRY principle by answering some of these questions with a blog post.

MVC

The first place to start digging into the MVC pattern is to look at the Wikipedia entry. That’ll get you a nice brief summary of the pattern along with a list of resources.

In MVC, the Model represents the information (the data) of the application and the business rules used to manipulate the data, the View corresponds to elements of the user interface such as text, checkbox items, and so forth, and the Controller manages details involving the communication to the model of user actions such as keystrokes and mouse movements.

trygve If you’re really into it, you can go directly to the source and read the original papers from Trygve Reenskaug, the inventor of the pattern.

There you’ll learn from the original paper (pdf) that the initial name for the pattern was Thing-Model-View-Editor. The pattern was baked via a process of extracting, improving, and articulating existing command and control patterns used in the operation of Norwegian ship yards in order to streamline and improve operations.

MVP

That ought to get you going with the MVC pattern. Now onto Model View Presenter, which was a response to the inadequacies of the MVC pattern when applied to modern component based graphical user interfaces. In modern GUI systems, GUI components themselves handle user input such as mouse movements and clicks, rather than some central controller.

MVP was popularized by Taligent in this paper on the subject (pdf). More recently, Martin Fowler suggested retiring this pattern in favor of two variants: Supervising Controller and Passive View.

The Difference?

So what’s the diff between MVC and MVP? Using GitHub, here it is!

246

Sorry, bad joke but I couldn’t resist.

The two patterns are similar in that they both are concerned with separating concerns and they both contain Models and Views. Many consider the MVP pattern to simply be a variant of the MVC pattern. The key difference is in how both patterns solve the following question: Who handles the user input?

With MVC, it’s always the controller’s responsibility to handle mouse and keyboard events. With MVP, GUI components themselves initially handle the user’s input, but delegate to the interpretation of that input to the presenter. This has often been called “Twisting the Triad”, which refers to rotating the three elements of the MVC triangle and replacing the “C” with “P” in order to get MVP.

What About The Web?

If you were playing close attention, most of these articles focus on rich client applications. Applying these patterns to the web is a very different beast because of the stateless nature of the web.

ASP.NET WebForms, for example, attempts to emulate the rich client development paradigm via the use of ViewState. This is why many attempts to apply patterns to ASP.NET focus on the MVP pattern because the MVP pattern is more appropriate for a rich client application with GUI components. A while back I even tossed my Supervising Controller sample into the ring. The Patterns and Practices group at Microsoft ship an MVP Bundle for ASP.NET.

However, many web platforms embrace the stateless nature of the web and forego attempting to simulate a state-full rich client development environment. In such systems, a tweaked MVC pattern is more applicable.

This pattern has been adjusted for the Web for your application development enjoyment.

AFAIK, Struts, a Java web framework, is one of the first widely used web frameworks employing the MVC pattern, though most people now look at Rails as being the tipping point that really brought MVC to the web and popularized the MVC pattern for web applications.

ASP.NET MVC is a new (in development) alternative framework for ASP.NET developers that makes it easy for developers to follow the MVC pattern. This framework employs the MVC pattern rather than the MVP pattern because it does not attempt to emulate rich client development, and thus the MVC pattern is more appropriate.

More Reading

There’s a lot of good content out there that puts these patterns into historical and categorical perspective. Besides the links already mentioned in this paper, I recommend checking out…

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

44 responses

  1. Avatar for Dragan Panjkov
    Dragan Panjkov June 16th, 2008

    give us some more of this :)

  2. Avatar for C0der
    C0der June 16th, 2008

    WinMerge is awesome!

  3. Avatar for Justin - Web Development Blog
    Justin - Web Development Blog June 16th, 2008

    The WinMerge Joke was amusing. To be honest until now I didn't know the difference between MVC and MVP. Thanks.

  4. Avatar for gb
    gb June 16th, 2008

    Hi,
    lets suppose you have both a webApp and WinApp and you wanted both to share some sort Mvc or MVP .
    What would you use?

  5. Avatar for Josh
    Josh June 16th, 2008

    I have been reading a ton on the Web Client Factory, and also on ASP.NET MVC, could you maybe do a write up comparing these two factories/frameworks which would be great for developers to see Microsoft's opinions on the frameworks that they make available to the development community.
    thanks!

  6. Avatar for Craig Shoemaker
    Craig Shoemaker June 16th, 2008

    Good comparison, Phil :)
    I also did a podcast/screencast series on MVP Design Patterns Bootcamp: Model View * Patterns in case anyone wants to see it built up from scratch.

  7. Avatar for David Tchepak
    David Tchepak June 16th, 2008

    Thanks for the helpful post Phil.
    I also found this description on the MVC# site a good complement to your post.

  8. Avatar for XiangQi
    XiangQi June 16th, 2008

    In China, we can not read the wikipedia.org :(

  9. Avatar for Lamin Barrow
    Lamin Barrow June 16th, 2008

    Thanks for the post, you have helped demystify the MVC pattern a bit.

  10. Avatar for Kevin Kerr
    Kevin Kerr June 16th, 2008

    Good post! Maybe sometime you could cover M-V-VM too :) Although that is probably more WPF specific. I did some small coverage of it here.

  11. Avatar for Javier Lozano
    Javier Lozano June 16th, 2008

    Hey Phil, I tried the WinMerge thing but I was unable to get the same result as you. What am I doing wrong?!!? :P

  12. Avatar for Neal Blomfield
    Neal Blomfield June 17th, 2008

    You forgot the other alternative to ASP.NET that allows .NET developers to feel the MVC love - MonoRail!

  13. Avatar for Kevin Berridge
    Kevin Berridge June 17th, 2008

    Great post! Describing MVP in terms of the problem it evolved to solve makes it much easier to understand. Thanks.

  14. Avatar for Angel Escobedo
    Angel Escobedo June 17th, 2008

    Here is the start point for best practices in web development, i think that this is a nice shoot for .net for include and extend mvc pattern in this framework, for my part, I'll be waiting and follow closely the evolution of this new form of work for many developer, longing that some day mvc.net be as complex framework as those that already exist for other languages like Java

  15. Avatar for Jonas
    Jonas June 18th, 2008

    ... trying again, sorry ...
    MVC, MVP, PresentationModel, Model-View-ViewModel ... this somehow reminds me" of 'Life Of Brian': The Judean People's Front, The People's Front of Judea, The Popular Front of Judea ...
    For rich-clients, I also recommend to read the exellent series of Jeremmy Miller
    "Build your own CAB"

  16. Avatar for Andrei Rînea
    Andrei Rînea June 19th, 2008

    Just like gb said above ("suppose you have both a webApp and WinApp and you wanted both to share some...") I must ask too:
    Using ASP.NET MVC can you share your controllers and models in a Windows Forms application? Can you swap your models ala provider pattern?
    Thanks.

  17. Avatar for Alex
    Alex June 23rd, 2008

    "This framework (ASP.NET MVC) employs the MVC pattern rather than the MVP pattern because it does not attempt to emulate rich client development, and thus the MVC pattern is more appropriate."
    Does this statement suggest that the ASP.NET MVC framework should not attempt to emulate richer client user interfaces?
    I have been using MVP and building complex user interfaces, leveraging third party tools and Ajax, and I have found success. With MVC, I hope to be able to build complex user interfaces as I have been doing with MVP once third party control support is more abundant.
    My point - I expect this ASP.NET MVC framework to be enable complex user interface development, emulating a richer clients. I am hoping it is just the way I read this statement that made me think twice.
    Will the ASP.NET MVC framework promote more complex user interfaces? At this point, many of the examples available are more simplistic.

  18. Avatar for haacked
    haacked June 23rd, 2008

    @Alex I should be more clear. We don't attempt to emulate the control statefulness of a rich client application by shuttling state back and forth within an opaque ViewState field.
    You can still write rich client like apps by simply keeping the state for controls within the client, ala Ajax and Javascript.

  19. Avatar for David Murphy
    David Murphy June 24th, 2008

    We've been using an implementation of MVP in our ASP.NET production environment for over a year now and it is has proved to be a very easy to use methodology and resulted in a lot of re-usable code, one of our initial aims.
    With the Model decoupled from the View entirely we are able to gradually migrate our Model code into our web services/WCF layer, which has resulted in a much more maintainable code base than we previously had as well as rationalising our systems to have a more unified data access layer, removing duplication and clearly defining our business objects.

  20. Avatar for Arnold Castro
    Arnold Castro July 7th, 2008

    Hi Phil,
    First of all I would like to commend you for the article you made comparing MVP and MVC patterns. I have a question though, we are about to build a huge and web long-term web application and we are currently searching for a good asp.net pattern and I think MVC is a good candidate for us. My question is, is it safe to implement the MVC framework today even though it is Beta? Thank you very much.
    Regards,
    Arnold

  21. Avatar for Yunus Özen
    Yunus Özen July 8th, 2008

    Hi, Phil. what do you think about this issue : http://java.sys-con.com/read/513263_1.htm

  22. Avatar for Binoj Antony
    Binoj Antony July 12th, 2008

    Nice article, stumbled upon it from Simons blog

  23. Avatar for A Jose
    A Jose July 13th, 2008

    Only after seeing your WinMerge picture, I could understand the diff btw MVC and MVP

  24. Avatar for Duarte Nunes
    Duarte Nunes July 16th, 2008

    Hi Phil,
    Another great post! I have just one related question: is it sound to use ASP.NET MVC as a View belonging to an MVP implementation (as opposed to using plain old WebForms)? In that scenario, the MVP Presenter would communicate with the MVC View through the MVC Controller (and through the *Data class used by that controller). So, the Controller would in fact be implemented as the Presenter, leaving the MVC with just the V. Seems weird, but since the MVC is not the main feature in ASP.NET, it also seems right. I would appreciate some thoughts : )
    Thanks,
    Duarte

  25. Avatar for Ervin Ter
    Ervin Ter July 20th, 2008

    Nice article. I get to know more about MVC and MVP from here. Thans Phil

  26. Avatar for BillKrat
    BillKrat August 2nd, 2008

    After having read Mike Potel and Martin Fowler I thought I had a clear understanding... Your blog raised some more questions (and laughter - the Difference). I use to understand the difference to be the "levels of abstraction" (Mike Potel) but more importantly for the reasons you noted in your MVP paragraph. I further believed that things like Passive View and MVC where for the old world as long as we're using Microsoft controls and databinding. So I must admit I was somewhat confused when Scott Guthries ASP.NET "MVC" emerged...
    The muddied waters are my failure to comprehend how "TWisting the Triad" can be called MVC; the ASP.NET controls still handle the input and its events are processed in their respective presenters. The ASP.NET controls are smarter than they've ever been (and getting smarter).
    Can you see where it is as clear as mud and why your "Difference" was somewhat embarrassing for me as we have an Agile environment and I laughed like a lune during a quite time in a room of developers.

  27. Avatar for Lindsay
    Lindsay September 30th, 2008

    Thanks for the article, Phil. It's a good primer for some people I work with to get an idea what MVC is all about.
    Do you know or can you tell me how to find out whether there's a projected date for release for MVC? I would love to use it here: we have several projects that would benefit from it, but we aren't allowed to use things that aren't officially released. I have heard rumors that it won't be out till 2010 but I can't find any real information one way or the other.

  28. Avatar for hARI
    hARI October 7th, 2008

    HI CAN ANY ONE HELP IN UNDERSTANDING MVCP .. WHERE MVP PATTERN HAS THE CONTROLLOER.
    BASICALLY IT WILL WORK ON ALL THE LOGIC LIKE STATE MANAGEMENT/ SESSION / PAGE NAVIGATION AND INTERACTING WITH MODEL.
    IF ANY ONE HAS THE EXAMPLE IT WOULD BE GREAT...

  29. Avatar for Koistya `Navin
    Koistya `Navin January 31st, 2009

    Comparison MVC and MVP with WinMerge is bomb! I was comparing it with Araxis Merge before that :-)

  30. Avatar for Evan Freeman
    Evan Freeman February 10th, 2009

    MVC / MVC WinDiff == Epic Funny thats just awsome.

  31. Avatar for jockeyvn
    jockeyvn December 18th, 2009

    Thanks for Article, I think in MVP Model, the Presenter will pass called from View and update to View. Anyway, it is more security

  32. Avatar for Mandeepinder
    Mandeepinder February 3rd, 2010

    Is it possible to use typeddataset in MVP pattern?
    if we can use then what will be the advantage and disadvantages of using them?

  33. Avatar for Novice
    Novice February 21st, 2010

    I am a but surprised with the fact that nobody mentioned about refactoring. Let's assume I have asp.net Webform application and I want to restructure it with better UI pattern. I heard good things about asp.net mvc but I don't think it can handle web-form very well. So at this point, the only way to restructure the UI seems to be MVP. Am I getting it right?

  34. Avatar for Thyagaraju Govardhan
    Thyagaraju Govardhan May 22nd, 2010

    Thanks for the article Phil.

  35. Avatar for Don
    Don January 21st, 2011

    From what I understand, the MVC pattern would be more appropriate to embedded systems and the industries (machinery), while the MVP pattern is more specific to computer applications and/or data processing applications. Or am I getting all this wrong?
    Thank you for the article.

  36. Avatar for Buzzer
    Buzzer April 19th, 2011

    A-hole! Nah just kiddin'! That was pretty funny actually!
    I'm in the Middle of writing a paper for school related to this topic and came across this post.
    You always find ways to dumb things down to my level. I'm starting to think that you are just really a dumb guy that knows how to write really well. hahahaha
    Thanks a lot Phil!

  37. Avatar for yvette
    yvette June 19th, 2011

    WinMerge joke is a broken link :(... i really really wanted to see it

  38. Avatar for sampath
    sampath July 6th, 2011

    NICE ONE

  39. Avatar for RainingDay'
    RainingDay' October 22nd, 2011

    Which of the web application using the MVC?

  40. Avatar for Java Developer
    Java Developer June 27th, 2012

    This is probably one of the best detailed explanation of MVC and MVP. I read a few articles and was getting confused.

  41. Avatar for firat
    firat January 18th, 2013

     I agree with the distinction of MVC and MVP is in how you handle user input.

    http://firatatagun.com

  42. Avatar for Lelala
    Lelala April 14th, 2013

    As so often in software engineering: This is just watching the same picture from different chairs, so the difference is just marginal, if not only esoterical/philosophical.
    I'm pretty sure, you could build something like Amazon with all of the paradigms around - so its up to you and your team and the tools you have available, that matters much more than the question which pattern is better.

    regards,
    Lelala
    http://www.lelala.de

  43. Avatar for Leke
    Leke November 16th, 2015

    Is this line right?

    > The key difference is suggested by the problem that the MVP pattern sought to solve with the MVP pattern.

    Shouldn't it be,

    > The key difference is suggested by the problem that the MVP pattern sought to solve with the MVC pattern.

  44. Avatar for matz keira
    matz keira September 20th, 2016

    Hello, I'm Olgierd and interested in your article. So may I translate yours into my blog? I will put the link to go back your blog and license. If you're ok, is there something you want to put any text? Lastly here is my blog: https://medium.com/@olgierdme