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

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 WinMerge, here it is!

WinMerge - [MVP.txt - mvc.txt]

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 suggested by the problem that the MVP pattern sought to solve with the MVP pattern. 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…

What others have said

Requesting Gravatar... Dragan Panjkov Jun 16, 2008 3:52 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
give us some more of this :)
Requesting Gravatar... C0der Jun 16, 2008 4:12 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
WinMerge is awesome!
Requesting Gravatar... Justin - Web Development Blog Jun 16, 2008 4:35 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
The WinMerge Joke was amusing. To be honest until now I didn't know the difference between MVC and MVP. Thanks.
Requesting Gravatar... gb Jun 16, 2008 5:32 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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?
Requesting Gravatar... Josh Jun 16, 2008 5:41 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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!
Requesting Gravatar... Craig Shoemaker Jun 16, 2008 6:06 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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.
Requesting Gravatar... David Jun 16, 2008 9:57 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Thanks for the helpful post Phil.

I also found this description on the MVC# site a good complement to your post.
Requesting Gravatar... XiangQi Jun 16, 2008 11:55 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
In China, we can not read the wikipedia.org :(
Requesting Gravatar... Lamin Barrow Jun 16, 2008 7:33 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Thanks for the post, you have helped demystify the MVC pattern a bit.
Requesting Gravatar... Kevin Kerr Jun 17, 2008 1:07 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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.
Requesting Gravatar... Javier Lozano Jun 17, 2008 1:26 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Hey Phil, I tried the WinMerge thing but I was unable to get the same result as you. What am I doing wrong?!!? :P
Requesting Gravatar... Neal Blomfield Jun 17, 2008 6:16 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
You forgot the other alternative to ASP.NET that allows .NET developers to feel the MVC love - MonoRail!
Requesting Gravatar... Kevin Berridge Jun 17, 2008 6:52 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Great post! Describing MVP in terms of the problem it evolved to solve makes it much easier to understand. Thanks.
Requesting Gravatar... Angel Escobedo Jun 18, 2008 2:42 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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
Requesting Gravatar... Jonas Jun 18, 2008 11:19 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
... 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"
Requesting Gravatar... Andrei Rinea Jun 19, 2008 11:05 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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.
Requesting Gravatar... Alex Jun 23, 2008 7:07 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
"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.
Requesting Gravatar... haacked Jun 24, 2008 12:40 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
@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.
Requesting Gravatar... David Murphy Jun 24, 2008 7:52 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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.
Requesting Gravatar... Arnold Castro Jul 07, 2008 5:29 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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
Requesting Gravatar... Yunus Özen Jul 09, 2008 12:21 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Hi, Phil. what do you think about this issue : http://java.sys-con.com/read/513263_1.htm
Requesting Gravatar... Binoj Antony Jul 12, 2008 10:48 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Nice article, stumbled upon it from Simons blog
Requesting Gravatar... A Jose Jul 13, 2008 7:08 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Only after seeing your WinMerge picture, I could understand the diff btw MVC and MVP
Requesting Gravatar... Duarte Nunes Jul 16, 2008 6:46 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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
Requesting Gravatar... Ervin Ter Jul 20, 2008 10:59 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Nice article. I get to know more about MVC and MVP from here. Thans Phil
Requesting Gravatar... BillKrat Aug 02, 2008 9:59 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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.
Requesting Gravatar... Lindsay Sep 30, 2008 4:31 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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.
Requesting Gravatar... hARI Oct 07, 2008 3:24 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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...
Requesting Gravatar... Koistya `Navin Jan 31, 2009 8:28 PM
# Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Comparison MVC and MVP with WinMerge is bomb! I was comparing it with Araxis Merge before that :-)
Requesting Gravatar... Evan Freeman Feb 10, 2009 6:27 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
MVC / MVC WinDiff == Epic Funny thats just awsome.
Requesting Gravatar... jockeyvn Dec 18, 2009 9:47 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Thanks for Article, I think in MVP Model, the Presenter will pass called from View and update to View. Anyway, it is more security
Requesting Gravatar... Mandeepinder Feb 03, 2010 7:29 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Is it possible to use typeddataset in MVP pattern?
if we can use then what will be the advantage and disadvantages of using them?
Requesting Gravatar... Novice Feb 21, 2010 11:11 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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?
Requesting Gravatar... Thyagaraju Govardhan May 22, 2010 2:50 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Thanks for the article Phil.
Requesting Gravatar... Don Jan 22, 2011 1:20 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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.
Requesting Gravatar... Buzzer Apr 19, 2011 11:23 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
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!
Requesting Gravatar... yvette Jun 19, 2011 11:49 AM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
WinMerge joke is a broken link :(... i really really wanted to see it
Requesting Gravatar... sampath Jul 06, 2011 6:21 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To As
NICE ONE
Requesting Gravatar... RainingDay' Oct 22, 2011 7:40 PM
# re: Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask
Which of the web application using the MVC?

What do you have to say?

(will show your gravatar)
Please add 2 and 1 and type the answer here: