Model view controller
(→See also) |
(→See also) |
||
Line 49: | Line 49: | ||
*[[Observer]] | *[[Observer]] | ||
* [http://youtube.com/watch?v=YYvOGPMLVDo The MVC song] | * [http://youtube.com/watch?v=YYvOGPMLVDo The MVC song] | ||
− | * [http://heim.ifi.uio.no/~trygver/1979/mvc-1/1979-05-MVC.pdf MVC Paper] - The original paper describing the MVC Pattern - [[Trygve Reenskaug]] 1979 | + | * [http://heim.ifi.uio.no/~trygver/1979/mvc-1/1979-05-MVC.pdf MVC Paper] - The original paper describing the MVC Pattern - [[Trygve Reenskaug]] 1979. More details of Trygve's involvement can be found [http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html here]. |
Revision as of 17:14, 20 August 2009
The Model View Controller (MVC) is one of the oldest architectural patterns. It is still widely used in web and application programming.
The general premise is to separate an application into three distinct parts:
- Model: The underlying model of the data, this is often provided by a back-end database.
- View: The interface with the web client/browser or the application's GUI.
- Controller: The logic (sometimes called 'business logic') that interfaces between the view and the model. In OO terms, the "controller offers facilities to change the state of the model."
The MVC is often considered circular in form, with the model providing data for the view, which uses the controller to update the model. However, in some situations the controller is thought to sit between the view and the model.
Ward's wiki considers both of these options incorrect [1]. The controller should simply exist to promote communication and validation between the model and the view. It should provide ways to change the view, either through direct calls or the use of an Observer. Controversy exists on whether the MVC should be considered an OO design pattern at all.
Contents |
Patterns
So, lets consider the variations of MVC.
MVC-Observer-Strategy
This model is the original MVC pattern proposed by the developers of Smalltalk. This model is also Sun's proposed structure of MVC in J2EE.
MVC-Mediator
This is the pattern that the developers of Apple's Cocoa framework believe is MVC, they even made a song about it.
- Controller resembles the Mediator between Model and View
MVC as an Input-Output Process
The diagram above shows how MVC can be viewed as a slight deviation from the OO paradigm. This is one way to argue that MVC is not OO [2].
MVC as a Distributed Architecture
This pattern is often used by those in web application development and is often know as MVC.
- View: The graphics/markup coding that provides a user interface to a remote user (i.e. in a web browser)
- Controller: The systems business logic. A distinct layer between the Model and the View. Provides a handling of user state, if necessary, and any behavioural modifications required to the persistent model.
- Model: A set of data objects that are responsible for the underlying persistence of a system. Usually these classes form the interface to an underlying DB.
External links
- Model View Controller - What Ward's wiki has to say about the MVC
- What's a Controller anyway? has loads of interesting history. Note the comment by Ralph Johnson about half way down.
- MVC's OO Nature - A discussion on Ward's wiki as to whether the MVC is appropriate or even valid for OOD.
- GUI Architectures by Martin Fowler
- MVC & MVP
See also
- Architectural patterns
- Presentation separation idiom
- Observer
- The MVC song
- MVC Paper - The original paper describing the MVC Pattern - Trygve Reenskaug 1979. More details of Trygve's involvement can be found here.