Skip to content
Search

Model View Controller pattern

lastmod 2025-11-06created 2015-06-197 edits

Model–View–Controller (MVC) is an architectural pattern used in software engineering. Used successfully, this pattern separates business logic from the user interface, producing applications in which the visual elements and the business logic running behind them can easily be changed without affecting each other. In MVC, the model represents the application's information (data), the view represents user interface elements such as text and checkbox items, and the controller manages the interaction between the data and the business logic.

ModelViewControllerDiagram2.gif

Category

Model

The model represents data and the rules that govern access to and updates of this data. In enterprise software, a model often serves as a software approximation of a real-world process.

Represents the data structure. A model class generally contains functions for retrieving, inserting, and updating data.

View

The view renders the contents of a model. It specifies exactly how the model data should be presented. If the model data changes, the view must update its presentation as needed. This can be achieved by using a push model, in which the view registers itself with the model for change notifications, or a pull model, in which the view is responsible for calling the model when it needs to retrieve the most current data.

Represents the part shown to the user.

Controller

The controller translates the user's interactions with the view into actions that the model will perform. In a stand-alone GUI client, user interactions could be button clicks or menu selections, whereas in an enterprise web application, they appear as GET and POST HTTP requests. Depending on the context, a controller may also select a new view — for example, a web page of results — to present back to the user.

Generally operates between the model and the view (or whatever handles HTTP requests and generates web pages).

History

MVC was first introduced in 1979 by Trygve Reenskaug, who was working on Smalltalk at Xerox PARC. The related implementation was described in depth in the influential paper "Applications Programming in Smalltalk-80: How to use Model-View-Controller".

MVC has several derivative patterns; the most widely known of them (because Microsoft used it) is the Model View Presenter pattern, which began to appear in the early 1990s. This pattern was designed as an evolution of MVC. However, Model-View-Controller is still very widely used.

In November 2002, the W3C voted to include the MVC structure in the XForms architecture for future web applications. This specification will soon be integrated into the XHTML 2.0 specification. More than 20 vendors currently support XForms frameworks with MVC integrated into their application stacks.

MVC1 vs MVC2 debate

This is completely wrong.

  • There is only MVC and not MVC1 or MVC 2.
  • MVC is a design pattern. MVC does not depend on or require Struts.
  • Struts facilitates applying the MVC pattern, however it can also implement Model 1.
  • MVC1 is NOT synomonous with model1. (synomonous: synonym)
  • MVC2 is NOT synomonous with model2. (synomonous: synonym)
  • Model 2 most properly describes the application of MVC in a Web-Application context.

An easier-to-read version

Think_about_mvc_pattern.png

See also

Favorite site

author Zer0 sitemap