Model–view–controller

From Wikipedia, the free encyclopedia
  (Redirected from Model-View-Controller)
Jump to: navigation, search

Model–view–controller (MVC) is a software architecture pattern which separates the representation of information from the user's interaction with it.[1][2] The model consists of application data, business rules, logic, and functions. 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 bar chart for management and a tabular view for accountants. The controller mediates input, converting it to commands for the model or view.[3] The central ideas behind MVC are code reusability and separation of concerns.[4]

Contents

Component interactions [edit]

A typical collaboration of the MVC components

In addition to dividing the application into three kinds of components, 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 (e.g., by scrolling through a document). It can also 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 to the user.

Use in web applications [edit]

Although originally developed for personal computing, Model View Controller has been widely adapted as an architecture for World Wide Web applications in all major programming languages. Several commercial and noncommercial application frameworks have been created that enforce the pattern. 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 took a thin client approach that placed almost the entire model, view and controller logic 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).

History [edit]

MVC was one of the seminal insights of the early field of graphical user interfaces, and one of the first works to describe and implement software constructs in terms of their responsibilities.[8]

Trygve Reenskaug introduced MVC into Smalltalk-76 while visiting Xerox Parc,[9][10] in the 70s; next, in the 80s, Jim Althoff and others implemented a version of MVC for the Smalltalk-80 class library. Only later MVC was expressed as a general concept, in a 1988 article.[11]

This first MVC concept defined Controller as "the module that deals with input" (similarly to how the View deals with output). This definition has no place any more in a modern application, because its role is taken up by a combination of the View and the modern OSs and frameworks.

The Controller, in modern applications of 2000s, is a module, or an intermediary section of code, that mediates communication (between the Model and View) and unifies validation, using either direct calls or the Observer — to decouple the Model from the View in the active Model.[12]

Other aspects of the MVC also evolved, but as a variant of the original concept, and because "parts of classic MVC don't really make sense for rich clients these days":[13] HMVC, MVA, MVP, MVVM, and others that adapted MVC to different contexts.

See also [edit]

References [edit]

  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 James 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. ^ Martin Fowler, GUI Architectures
  5. ^ 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. ^ http://c2.com/cgi/wiki?ModelViewControllerHistory
  9. ^ Notes and Historical documents from Trygve Reenskaug, inventor of MVC.
  10. ^ "A note on DynaBook requirements", Trygve Reenskaug, 22 March 1979, SysReq.pdf.
  11. ^ Krasner, Glenn E.; Stephen T. Pope (Aug/Sep 1988). "A cookbook for using the model-view controller user interface paradigm in Smalltalk-80". The JOT (SIGS Publications).  Also published as "A Description of the Model-View-Controller User Interface Paradigm in the Smalltalk-80 System" (Report), ParcPlace Systems; Retrieved 2012-06-05.
  12. ^ http://msdn.microsoft.com/en-us/library/ff649643.aspx
  13. ^ The evolution of MVC and other UI architectures from Martin Fowler.

External links [edit]