Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. This is done to separate internal representations of information from the ways information is presented to and accepted from the user.
Traditionally used for desktop graphical user interfaces (GUIs), this pattern became popular for designing web applications. Popular programming languages have MVC frameworks that facilitate implementation of the pattern.
One of the seminal insights in the early development of graphical user interfaces, MVC became one of the first approaches to describe and implement software constructs in terms of their responsibilities.
Trygve Reenskaug created MVC while working on Smalltalk-79 as a visiting scientist at the Xerox Palo Alto Research Center (PARC) in the late 1970s.: He wanted a pattern that could be used to structure any program where users interact with a large, convoluted data set. His design initially had four parts: Model, View, Thing, and Editor. After discussing it with the other Smalltalk developers, he and the rest of the group settled on Model, View, and Controller instead.
In their final design, a Model represents some part of the program purely and intuitively. A View is a visual representation of a Model, retrieving data from the Model to display to the user and passing requests back and forth between the user and the Model. A Controller is an organizational part of the user interface that lays out and coordinates multiple Views on the screen, and which receives user input and sends the appropriate messages to its underlying Views. This design also includes an Editor as a specialized kind of Controller used to modify a particular View, and which is created through that View.
Smalltalk-80 supports a version of MVC that evolved from this one. It provides abstract
Controller classes as well as various concrete subclasses of each that represent different generic widgets. In this scheme, a
View represents some way of displaying information to the user, and a
Controller represents some way for the user to interact with a
View is also coupled to a model object, but the structure of that object is left up to the application programmer. The Smalltalk-80 environment also includes an "MVC Inspector," a development tool for viewing the structure of a given model, view, and controller side-by-side. 
In 1988, an article in The Journal of Object Technology (JOT) by two ex-PARC employees presented MVC as a general "programming paradigm and methodology" for Smalltalk-80 developers. However, their scheme differed from both Reenskaug et al.'s and that presented by the Smalltalk-80 reference books. They defined a view as covering any graphical concern, with a controller being a more abstract, generally invisible object that receives user input and interacts with one or many views and only one model.
The MVC pattern subsequently evolved, giving rise to variants such as hierarchical model–view–controller (HMVC), model–view–adapter (MVA), model–view–presenter (MVP), model–view–viewmodel (MVVM), and others that adapted MVC to different contexts.
The use of the MVC pattern in web applications grew after the introduction of NeXT's WebObjects in 1996, which was originally written in Objective-C (that borrowed heavily from Smalltalk) and helped enforce MVC principles. Later, the MVC pattern became popular with Java developers when WebObjects was ported to Java. Later frameworks for Java, such as Spring (released in October 2002), continued the strong bond between Java and MVC.
In 2003, Martin Fowler published Patterns of Enterprise Application Architecture, which presented MVC as a pattern where an "input controller" receives a request, sends the appropriate messages to a model object, takes a response from the model object, and passes the response to the appropriate view for display.: This is close to the approach taken by the Ruby on Rails framework (August 2004), which has the client send requests to the server via an in-browser view, where they are handled by a controller, which then communicates with the appropriate model objects. The Django framework (July 2005, for Python) put forward a similar "MTV" (Model Template View) take on the pattern, in which a view retrieves data from models and passes it to templates for display. Both Rails and Django debuted with a strong emphasis on rapid deployment, which increased MVC's popularity outside the traditional enterprise environment in which it has long been popular.
- The central component of the pattern. It is the application's dynamic data structure, independent of the user interface. It directly manages the data, logic and rules of the application.
- Any representation of information such as a chart, diagram or table. Multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants.
- Accepts input and converts it to commands for the model or view.
In addition to dividing the application into these components, the model–view–controller design defines the interactions between them.
- The model is responsible for managing the data of the application. It receives user input from the controller.
- The view renders presentation of the model in a particular format.
- The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.
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 designs can vary significantly from the traditional description here.
As Alan Kay wrote in 2003 the original motivation behind the MVC was to allow creation of a graphical interface for any object. That was outlined in detail in Richard Pawson's book called "Naked Objects".
Use in web applications
Although originally developed for desktop computing, MVC has been widely adopted as a design for World Wide Web applications in major programming languages. Several web frameworks have been created that enforce the pattern. These software frameworks vary in their interpretations, mainly in the way that the MVC responsibilities are divided between the client and server.
Some web MVC frameworks take a thin client approach that places almost the entire model, view and controller logic on the server. In this approach, the client sends either hyperlink requests or form submissions 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.
- Multitier architecture
- Hierarchical model–view–controller
- Model–view–view model
- Entity-Control-Boundary pattern
- Observer pattern
- Separation of concerns
- Strategy pattern
- "The Principles of Clean Architecture by Uncle Bob Martin". YouTube.
- Reenskaug, Trygve; Coplien, James O. (20 March 2009). "The DCI Architecture: A New Vision of Object-Oriented Programming". Artima Developer. Archived from the original (html) on 23 March 2009. Retrieved 3 August 2019.
More deeply, the framework exists to separate the representation of information from user interaction.
- 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."
- Davis, Ian. "What Are The Benefits of MVC?". Internet Alchemy. Retrieved 2016-11-29.
- Model–View–Controller History. C2.com (2012-05-11). Retrieved on 2013-12-09.
- Notes and Historical documents from Trygve Reenskaug, inventor of MVC.
- "A note on DynaBook requirements", Trygve Reenskaug, 22 March 1979, SysReq.pdf.
- Fowler, Martin (2003). Patterns of Enterprise Application Architecture. Pearson Education, Inc. ISBN 0-321-12742-0.
- Goldberg, Adele (1984). Smalltalk-80: The Interactive Programming Environment. Addison-Wesley. ISBN 0-201-11372-4.
- Krasner, Glenn E.; Pope, Stephen T. (Aug–Sep 1988). "A cookbook for using the model–view controller user interface paradigm in Smalltalk-80". The Journal of Object Technology. SIGS Publications. 1 (3): 26–49. 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.
- The evolution of MVC and other UI architectures from Martin Fowler.
- "Ruby on Rails Guides". Retrieved March 19, 2022.
- "Django FAQ: Django appears to be a MVC framework, but you call the Controller the "view", and the View the "template". How come you don't use the standard names?". Retrieved March 19, 2022.
- Burbeck, Steve (1992) Applications Programming in Smalltalk-80:How to use Model–View–Controller (MVC)
- Simple Example of MVC (Model–View–Controller) Architectural Pattern for Abstraction
- Buschmann, Frank (1996) Pattern-Oriented Software Architecture.
- Gamma, Erich et al. (1994) Design Patterns
- Moore, Dana et al. (2007) Professional Rich Internet Applications: Ajax and Beyond: "Since the origin of MVC, there have been many interpretations of the pattern. The concept has been adapted and applied in very different ways to a wide variety of systems and architectures."
- Alan Kay (23 May 2003). "is squeak really object oriented ?". Squeak Foundation mailing list. Retrieved 26 October 2021.
- 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.
|Wikibooks has a book on the topic of: Computer Science Design Patterns/Model–view–controller|