Model–view–controller

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Model–View–Controller (MVC) is a type of computer user interface that separates the representation of information from the user's interaction with it.[1][2] The model consists of application data and business rules, and the controller mediates input, converting it to commands for the model or view.[3] A view can be any output representation of data, such as a chart or a diagram. Multiple views of the same data are possible, such as a pie chart for management and a tabular view for accountants. The central idea behind MVC is code reusability and separation of concerns. [4]

Contents

[edit] Component interactions

In addition to dividing the application into three kinds of component, the MVC design defines the interactions between them.[5]

  • A controller can send commands to its associated view to change the view's presentation of the model (for example, by scrolling through a document). It can send commands to the model to update the model's state (e.g. editing a document).
  • A model notifies its associated views and controllers when there has been a change in its state. This notification allows the views to produce updated output, and the controllers to change the available set of commands. A passive implementation of MVC omits these notifications, because the application does not require them or the software platform does not support them.[6]
  • A view requests from the Model the information that it needs to generate an output representation.

With the responsibilities of each component thus defined, MVC allows different views and controllers to be developed for the same model. It also allows the creation of general-purpose software frameworks to manage the interactions.[5]

[edit] Use in web applications

MVC has been adapted as an architecture for World Wide Web applications. Several commercial and noncommercial application frameworks have been created to enforce the design. These frameworks vary in their interpretations, mainly in the way that the MVC responsibilities are divided between the client and server.[7]

Early web MVC frameworks such as Java EE took a thin client approach that placed view and controller logic almost entirely on the server. In this approach, the client sends either hyperlink requests or form input to the controller and then receives a complete and updated web page (or other document) from the view; the model exists entirely on the server.[7] As client technologies have matured, frameworks such as JavaScriptMVC and Backbone have been created that allow the MVC components to execute partly on the client (see also AJAX).

[edit] History

The model-view-controller pattern was originally formulated in the late 1970s by Trygve Reenskaug at Xerox PARC, as part of the Smalltalk system.[8][9][10]

[edit] See also

[edit] References

  1. ^ "More deeply, the framework exists to separate the representation of information from user interaction." The DCI Architecture: A New Vision of Object-Oriented Programming - Trygve Reenskaug and Jim Coplien - March 20, 2009
  2. ^ "... the user input, the modeling of the external world, and the visual feedback to the user are explicitly separated and handled by three types of object." Applications Programming in Smalltalk-80(TM):How to use Model-View-Controller (MVC)
  3. ^ Simple Example of MVC (Model View Controller) Design Pattern for Abstraction
  4. ^ Best MVC Practices
  5. ^ a b Buschmann, Frank (1996) Pattern-Oriented Software Architecture
  6. ^ How to Use Model–View–Controller (MVC)
  7. ^ a b Leff, Avraham; James T. Rayfield (September 2001). "Web-Application Development Using the Model/View/Controller Design Pattern". IEEE Enterprise Distributed Object Computing Conference. pp. 118-127. 
  8. ^ Weisfeld, Matt A. (2004), The Object-Oriented Thought Process, Sams Publishing, p. 239, ISBN 9780672326110, http://books.google.com/books?id=QveDqVtLFIcC&pg=PA239 .
  9. ^ Liu, Chamond (2000), "Chapter 11. The venerable model-view-controller", SmallTalk, Objects, and Design, iUniverse, pp. 115–126, ISBN 9781583484906, http://books.google.com/books?id=W8_Une9cbbgC&pg=PA115 .
  10. ^ Goderis, Sofie (2007–2008), On the separation of user interface concerns: A Programmer's Perspective on the Modularisation of User Interface Code, Ph.D. thesis, Vrije Universiteit Brussels, p. 15, http://books.google.com/books?id=vS8y4by4NHQC&pg=PA15 .

[edit] Further reading

Personal tools
Namespaces

Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages