Model–view–controller

From Wikipedia, the free encyclopedia
  (Redirected from Model view controller)
Jump to: navigation, search

Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces. It divides a given software application into three interconnected parts, so as to separate internal representations of information from the ways that information is presented to or accepted from the user.[1][2]

Overview[edit]

As with other software design patterns, MVC expresses the "core of the solution" to a problem while allowing it to be adapted for each system.[3] It is better seen as a concept instead of a specific implementation. There are many implementations of the concept.

All MVC variants use the same division of components, but usually they differ in how those components interact.

Components[edit]

The central component of MVC, the model, captures the behavior of the application in terms of its problem domain, independent of the user interface.[4] The model directly manages the data, logic and rules of the application. A view can be any output representation of information, such as a chart or a diagram; multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants. The third part, the controller, accepts input and converts it to commands for the model or view.[5]

Interactions[edit]

Passive view[edit]

Passive view variant
  • The controller is the only component which can communicate with the model and the view. There is no direct communication between view and model.
  • The controller can send commands to the model to update the model's state (e.g., editing a document). It can also send commands to its associated view to change the view's presentation of the model (e.g., by scrolling through a document).
  • The controller polls the model for updates.
  • Also called model-view-adapter

Model - view - view model (MVVM)[edit]

This is a subvariant of passive view in which the controller also works as a model-view component, which transforms model data format in view data format and vice-versa.

Supervising controller[edit]

Supervising controller implementation
  • The controller communicates with the model and the view (as in passive view variant)
  • Difference from passive view: view and model also communicate between themselves. This may be implemented, for instance, with events or data binding.
  • The model notifies its associated views and controllers when there has been a change in its state.
  • The view requests information from the model that it uses to generate an output representation to the user.
  • The original MVC implementation used this variant.

Model - view - presenter (MVP)[edit]

There is not a consensus of what this variant currently means. Some sources define it as an synonym of passive view variant,[6] other define it as an synonym for supervising controller [7][7] and others define it as a synonym of MVC. Anyway, MVP is redundant, as it is already covered by supervising controller and passive view variants.

Use in web applications[edit]

Although originally developed for desktop computing, model–view–controller has been widely adopted as an architecture for World Wide Web applications in major programming languages. Several commercial and noncommercial web 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.[8]

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.[8] As client technologies have matured, frameworks such as AngularJS, Ember.js, JavaScriptMVC and Backbone have been created that allow the MVC components to execute partly on the client (also see Ajax).

History[edit]

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

Trygve Reenskaug introduced MVC into Smalltalk-76 while visiting Xerox Parc[10][11] in the 1970s. In the 1980s, Jim Althoff and others implemented a version of MVC for the Smalltalk-80 class library. It was only later, in a 1988 article in The Journal of Object Technology, that MVC was expressed as a general concept.[12]

The MVC pattern has subsequently evolved,[13] giving rise to variants such as 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. ^ Burbeck (1992): "... 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."
  3. ^ Gamma, Erich et al. (1994) Design Patterns
  4. ^ Burbeck, Steve (1992) Applications Programming in Smalltalk-80(TM):How to use Model–View–Controller (MVC)
  5. ^ Simple Example of MVC (Model View Controller) Design Pattern for Abstraction
  6. ^ http://msdn.microsoft.com/en-us/magazine/cc188690.aspx
  7. ^ a b http://www.wildcrest.com/Potel/Portfolio/mvp.pdf
  8. ^ a b Leff, Avraham; Rayfield, James T. (September 2001). "Web-Application Development Using the Model/View/Controller Design Pattern". IEEE Enterprise Distributed Object Computing Conference. pp. 118–127. 
  9. ^ Model View Controller History. C2.com (2012-05-11). Retrieved on 2013-12-09.
  10. ^ Notes and Historical documents from Trygve Reenskaug, inventor of MVC.
  11. ^ "A note on DynaBook requirements", Trygve Reenskaug, 22 March 1979, SysReq.pdf.
  12. ^ Krasner, Glenn E.; Pope, Stephen T. (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.
  13. ^ The evolution of MVC and other UI architectures from Martin Fowler.

External links[edit]