Model-view-controller

From Wiki @ Karl Jones dot com
Revision as of 03:38, 21 April 2016 by Karl Jones (Talk | contribs) (External links)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces.

Description

MVC 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.

As with other software patterns, MVC expresses the "core of the solution" to a problem while allowing it to be adapted for each system. Particular MVC architectures can vary significantly from the tradition model.

Components

The traditional MVC has three components:

  • The model describes the behavior of the application in terms of its problem domain, independent of the user interface.
    • The model directly manages the data, logic and rules of the application
  • The view generates output for the user
    • Multiple views of the same information are possible
  • The controller accepts input and converts it to commands for the model or view.

Interactions

In addition to dividing the application into three kinds of components, the model–view–controller design defines the interactions between them.

A 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).

A model stores data that is retrieved by the controller and displayed in the view. Whenever there is a change to the data it is updated by the controller.

A view requests information from the model that it uses to generate an output representation to the user.

MVC in web applications

Although originally developed for desktop computing, model–view–controller has been widely adopted as an architecture for web applications in major programming languages.

Frameworks

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.

History

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 requests with user data 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.

As client-side technologies have matured, frameworks such as AngularJS, Ember.js, JavaScriptMVC and Backbone.js have been created that allow the MVC components to execute partly on the client.

Ajax

See also Ajax (programming), which is commonly used with MVC-base web applications.

See also

External links