Difference between Model-View-Presenter and Model-View-Controller

Edit (24/3/09): I think this post serve as a good introduction to asp.net mvc. It explains about the underlying difference between asp.net mvc and webform

Fowler in the book Patterns of Enterprise Application coined the Model-View-Controller pattern, which started in 1970s as a part of the smalltalk platform. Ever since the architectural pattern has been widely used in many applications. It has also triggered the birth of numerous similar other patterns, such as Model-View-Presenter, Presenter First, Model-View-ViewModel, etc. I have discussed in another post about how to implement Model View Presenter pattern on a webform application. This time I want to discuss the difference between Model View Presenter/Supervising Controller (MVP) and Model View Controller (MVC).

Main Difference
The main difference between the two is how the manager (controller/presenter) sits in the overall architecture.

All requests goes first to the Controller
MVC pattern puts the controller as the main ‘guy’ in charge for running the show. All application request comes through straight to the controller, and it will decide what to do with the request.

Requests goes to controller. Calls the necessary models, and the construct the view

Giving this level of authority to the controller isn’t an easy task in most cases. Users interaction in an application happen most of the time on the View.

Thus to adopt MVC pattern in a web application, for example, the url need to become a way of instantiating a specific controller, rather than ‘simply’ finding the right View (webform/ html page) to render out. Every requests need to trigger the instantiation of a controller which will eventually produce a response to the user.

This is the reason why it’s alot more difficult to implement pure MVC using Asp.Net Webform. The Url routing system in Asp.Net webform by default is tied in to the server filesystem or IIS virtual directory structure. Each of these aspx files are essentially Views which will always get called and instantiated first before any other classes in the project. (Of course I’m overgeneralizing here. Classes like IHttpModule, IHttpHandler and Global.asax would be instantiated first before the aspx web form pages).

Url: http://some.cool.domain/Please/ListCar.aspx?Id=5


web form is tied in to the filesystem/IIS directory structure (Virtual directory, etc)

Asp.net MVC does it rather differently. It uses a heavy dose of ‘convention over configuration’ to map a URI with a controller. This is done through the System.Web.Routing class.

Controller for the ‘heavy lifting’
In order to serve the request, a Controller needs to work with the Models. Data are fetched, encapsulated in a nice Business Object like manner. It’s the Controller job to instantiate the View. After which, the Model then get passed on to the View for ‘rendering’.

In a typical web environment this often means, it’s the duty of the Controller to retrieve data from the database (Repository pattern is often use here), then renders out the html sent out to the client browser.

for e.g

public class PleaseController : Controller
{
    public IView ListAll()
    {
        // call database get all the models
        Model[] models = new Repository().FindAll();
        
        // pass the models to view
        View["models"] = models;

        // serve the response
        Return View();
    }
}

On the other hand
MVP (Supervising Controller) on the other hand, doesn’t mind for the View to take on a bigger role. View is the first object instantiated in the execution pipeline, which then responsible for passing any events that happens on itself to the Presenter.

The presenter then fetch the Models, and pass it back to the view for rendering. Example is explained in a greater detail in another post: Asp.Net MVC without ‘the framework’ part 1