Model-view-controller
Encyclopedia : M : MO : MOD : Model-view-controller
Model-view-controller (MVC) is a software architecture that separates an application's data model, user interface, and control logic into three distinct components so that modifications to one component can be made with minimal impact to the others.
MVC is often thought of as a software design pattern. However, MVC encompasses more of the architecture of an application than is typical for a design pattern. Hence the term architectural pattern may be useful (Buschmann, et al 1996), or perhaps an [aggregate design pattern].
Operation
In broad terms, constructing an application using an MVC architecture involves defining three classes of modules.- Model: The domain-specific representation of the information on which the application operates. The model is another name for the domain layer. Domain logic adds meaning to raw data (e.g. calculating if today is the user's birthday, or the totals, taxes and shipping charges for shopping cart items).
- View: Renders the model into a form suitable for interaction, typically a user interface element. MVC is often seen in web applications, where the view is the HTML page and the code which gathers dynamic data for the page.
- Controller: Responds to events, typically user actions, and invokes changes on the model and perhaps the view.
- Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention this data access layer, because it is understood to be underneath or encapsulated by the Model.
Though MVC comes in different flavors, control flow generally works as follows:
- The user interacts with the user interface in some way (e.g., user presses a button)
- A controller handles the input event from the user interface, often via a registered handler or callback.
- The controller accesses the model, possibly updating it in a way appropriate to the user's action (e.g., controller updates user's shopping cart). Complex controllers are often structured using the command pattern to encapsulate actions and simplify extension.
- A view uses the model to generate an appropriate user interface (e.g., view produces a screen listing the shopping cart contents). The view gets its own data from the model. The model has no direct knowledge of the view. (However, the observer pattern can be used to allow the model to indirectly notify interested parties – potentially including views – of a change.)
- The user interface waits for further user interactions, which begins the cycle anew.
A simple diagram depicting the relationship between the Model, View, and Controller is provided below. Note: the solid lines indicate a direct association, and the dashed line indicate an indirect association (i.e. Observer pattern).

Implementations
The pattern was [first described in 1979] by Trygve Reenskaug, then working on Smalltalk at Xerox research labs. The original implementation is described in depth in the influential paper [Applications Programming in Smalltalk-80(TM):How to use Model-View-Controller].Smalltalk's MVC implementation inspired many other GUI frameworks such as:
- The NeXTSTEP and OPENSTEP development environments encourage the use of MVC. Cocoa and GNUstep, based on these technologies, also use MVC.
- Microsoft Foundation Classes (MFC) (called Document/View architecture here)
- The Java Swing GUI library.
- The Qt Toolkit since Qt4 Release.
More recently there have been attempts to apply MVC architectures for web-based interfaces. In the design of web applications, MVC is also known as a "Model 2" architecture in Sun parlance. Complex web applications continue to be more difficult to design than traditional applications, and MVC is being pushed as a potential solution to these difficulties.
- JavaServer Faces, Apache Struts and Webwork2 are currently the most popular web oriented MVC implementations. Struts works at a page level; JSF works at a component level .
- XForms is an approach on building web based applications based on MVC, under development by [W3C]
- The WebObjects development/deployment environment is strongly based on MVC.
- CakePHP
- [Copix - PHP Framework]
- [MVC frameworks written in PHP (Wiki)]
- Zend Framework A light-weight framework for PHP. It is a new framework and has a way to go yet.
- Fusebox
- Mach-II
- Model-Glue for ColdFusion [Link]
- Maypole
- Catalyst
- Wicket
- Tapestry
- ZNF
- [Phrame]
- Symfony
- Apache Cocoon
- [Orbeon]
- [DragonPHP]
- [PHP on Trax]
- Radicore For either PHP 4 or 5
- Ruby on Rails
- TurboGears
- Django
- [Smart3]
- [Spring Framework]
- [Maverick for .Net]
- [Microsoft UIP]
- [Ingenious MVC] .Net MVC
- [ASWing] An opensource actionscript2 (Flash) implementation of the Java Swing library.
- [Code Igniter] A PHP MVC framework
- [MonoRail] An ActionPack inspired MVC framework from the Castle Project
- [Blokz] A PHP + PostgreSQL MVC Framework.
See also
- Trygve Reenskaug
- Design patterns
- Model 1
- Three-tier (computing)
- The Observer design pattern
- The Template Method design pattern
- The Presentation-abstraction-control pattern
External links
General information regarding MVC- [MVC Description in the Portland Pattern Repository]
- [Discussion of JavaServer Pages Model 2 architecture]
- [Model View Controller Overview]
- [Presentation]
- [Core J2EE Patterns - Front Controller]
- [MVC versus "Event Driven" Discussion]
- [What's a Controller Anyway]
- [PHP on Trax] (PDF), a presentation by John Peterson, creator of Trax
- [MVC Frameworks for PHP] (PDF), a presentation on general MVC principles, especially as applied to PHP
- [The Model-View-Controller Design Pattern for PHP] an implementation which utilises reusable XSL stylesheets for the View.
References
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
