Opentopia Directory Encyclopedia Tools

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. It's common to think of an application as having three main layers: presentation (UI), domain, and data access. In MVC, the presentation layer is split into controller and view. The most important separation is between presentation and domain; the View/Controller split is less so.

Though MVC comes in different flavors, control flow generally works as follows:

  1. The user interacts with the user interface in some way (e.g., user presses a button)
  2. A controller handles the input event from the user interface, often via a registered handler or callback.
  3. 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.
  4. 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.)
  5. The user interface waits for further user interactions, which begins the cycle anew.
Through decoupling of the model, view and controller components, each unit can change irrespective of the implementation of the other. For instance, a typical implementation of a web application will rely on the view component to layout HTML in response to a user's request. If, however, an XML response is required, only the view component need change (to an XML formatting component) while the model and controller remain the same.

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).
ModelViewControllerDiagram.png

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:

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.

See also

External links

General information regarding MVC Specific aspects of MVC or alternatives to MVC MVC frameworks in PHP

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.

Search Titles
0123456789
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ?

E-mail this article to:

Personal Message: