Model–view–controller
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
- Model View ViewModel
- Model–view–adapter
- Model–view–presenter
- Observer pattern
- Presentation–abstraction–control
[edit] References
- ^ "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
- ^ "... 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)
- ^ Simple Example of MVC (Model View Controller) Design Pattern for Abstraction
- ^ Best MVC Practices
- ^ a b Buschmann, Frank (1996) Pattern-Oriented Software Architecture
- ^ How to Use Model–View–Controller (MVC)
- ^ 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.
- ^ Weisfeld, Matt A. (2004), The Object-Oriented Thought Process, Sams Publishing, p. 239, ISBN 9780672326110, http://books.google.com/books?id=QveDqVtLFIcC&pg=PA239.
- ^ 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.
- ^ 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
- What Are The Benefits of MVC? - quotes at length from the Gang of Four (software)
- Krausner, Glenn E.; Stephen T. Pope (1988). A Description of the Model-View-Controller User Interface Paradigm in the Smalltalk-80 System (Report). ParcPlace Systems, Inc.. http://www.itu.dk/courses/VOP/E2005/VOP2005E/8_mvc_krasner_and_pope.pdf. Retrieved 2012-06-05.
- Model-View-Controller Pattern in WikiBooks
- Historical documents from Trygve Reenskaug, inventor of MVC