Monday 12 September 2011

MVP vs MVC

Common to both:

The Model: this term describes the business logic and comprises various business entites, or the other set of re-usable classes like those pertaining to data access, custom control classes, application configuration classes etc.

The View: basically the UI component. Within an .net web application, files such as *.aspx, *.ascx and Master pages make up The View

Model View Presenter

The user interacts with the UI of the site, the View, by requesting particular URLs which map to Action Methods of the view.
The view passes these calls to the presenter.
The presenter then decides what to do with these calls, often maniupulating some part of the business layer, such as the business entities, collectively know as the domain model, aka The Model.
The Model then fires events back to the presenter which is then also in charge of updating the view.

Model View Controller

The difference here is that we swap the Presenter with a Controller.
The Controller has no idea about the View.
In fact, the View can switch Controllers, eg based on who logged into the system, and a single Controller can be used by multiple Views.
The View subscribes to events which are triggered when the Model changes - hence the View is in sync with the Model from a data perspective.

The main difference between MVC and MVP is: The Presenter is are of and is responsible for updating the View whereas the Controller doesn't know anything about the View.

MVC is often described as an Compound Pattern':
The View-Model relationship can be seen as an 'Observer Pattern', in that the Model notifies the View (an observer) when it changes so the View can update itself

No comments:

Post a Comment