Model–View–Controller (MVC) is an architectural pattern used in software engineering. The pattern isolates “domain logic” (the application logic for the user) from input and presentation (GUI), permitting independent development, testing and maintenance of each.
The model is the domain-specific representation of the data upon which the application operates. Domain logic adds meaning to raw data (for example, calculating whether today is the user’s birthday, or the totals, taxes, and shipping charges for shopping cart items). When a model changes its state, it notifies its associated views so they can refresh.
Many applications use a persistent storage mechanism such as a database to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the model. Models are not data access objects; however, in very simple apps that have little domain logic there is no real distinction to be made. Also, the ActiveRecord is an accepted design pattern which merges domain logic and data access code – a model which knows how to persist itself.
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.
The controller receives input and initiates a response by making calls on model objects.
An MVC application may be a collection of model/view/controller triplets, each responsible for a different UI element.
MVC is often seen in web applications where the view is the HTML or XHTML generated by the app. The controller receives GET or POST input and decides what to do with it, handing over to domain objects (i.e. the model) that contain the business rules and know how to carry out specific tasks such as processing a new subscription.
* 1 History
* 2 Overview
* 3 Selected frameworks
o 3.1 GUI frameworks
+ 3.1.1 VCL
o 3.2 Combined frameworks
+ 3.2.1 Java: Java Platform, Enterprise Edition (Java EE)
+ 3.2.2 XForms
* 4 Implementations of MVC as GUI frameworks
* 5 Implementations of MVC as web-based frameworks
o 5.1 ABAP Objects
o 5.2 Actionscript
o 5.3 ASP
o 5.4 C++
o 5.5 ColdFusion
o 5.6 Flex
o 5.7 Groovy
o 5.8 Java
o 5.10 Informix 4GL
o 5.11 Lua
o 5.12 .NET
o 5.13 Perl
o 5.14 PHP
o 5.15 Python
o 5.16 Ruby
o 5.17 Smalltalk
o 5.18 XML
o 5.19 XQuery
* 6 See also
* 7 References
* 8 External links
MVC was first described in 1979 by Trygve Reenskaug, then working on Smalltalk at Xerox PARC. The original implementation is described in depth in the influential paper “Applications Programming in Smalltalk-80: How to use Model–View–Controller”.
There have been several derivatives of MVC. For example, Model View Presenter is used with the .NET Framework, and the XForms standard uses a “model-view-controller-connector architecture”. However, standard MVC remains popular.
Though MVC comes in different flavors, control flow is generally as follows:
1. The user interacts with the user interface in some way (for example, presses a mouse button).
2. The controller handles the input event from the user interface, often via a registered handler or callback and converts the event into appropriate user action, understandable for the model.
3. The controller notifies the model of the user action, possibly resulting in a change in the model’s state. (For example, the controller updates the user’s shopping cart.)
4. A view queries the model in order to generate an appropriate user interface (for example, the view lists the shopping cart’s contents). Note that the view gets its own data from the model. The controller may (in some implementations) issue a general instruction to the view to render itself. In others, the view is automatically notified by the model of changes in state (Observer) which require a screen update.
5. The user interface waits for further user interactions, which restarts the cycle.
Some implementations such as the W3C XForms also use the concept of a dependency graph to automate the updating of views when data in the model changes.
By decoupling models and views, MVC helps to reduce the complexity in architectural design and to increase flexibility and reuse of code.
 Selected frameworks
 GUI frameworks
The controller is represented by the visual forms created either in the form designer or via code.
 Combined frameworks
 Java: Java Platform, Enterprise Edition (Java EE)
Simple Version implementing Java Servlets and JavaServer Pages from Java EE:
The model is a collection of Java classes that form a software application intended to store, and optionally separate, data. A single front end class that can communicate with any user interface (for example: a console, a graphical user interface, or a web application).
The view is represented by JavaServer Page, with data being transported to the page in the HttpServletRequest or HttpSession.
The Controller servlet communicates with the front end of the model and loads the HttpServletRequest or HttpSession with appropriate data, before forwarding the HttpServletRequest and Response to the JSP using a RequestDispatcher.
The Servlet is a Java class, and it communicates and interacts with the model but does not need to generate HTML or XHTML output; the JSPs do not have to communicate with the model because the Servlet provides them with the information—they can concentrate on creating output.
Unlike the other frameworks, Java EE defines a pattern for model objects.
The model is commonly represented by entity beans, although the model can be created by a servlet using a business object framework such as Spring.
The view in a Java EE application may be represented by a JavaServer Page, which may be currently implemented using JavaServer Faces Technology (JSF). Alternatively, the code to generate the view may be part of a servlet.
The controller in a Java EE application may be represented by a servlet, which may be currently implemented using JavaServer Faces (JSF).
XForms is an XML format for the specification of a data processing model for XML data and user interface(s) for the XML data, such as web forms.
XForms stores the Model as XML elements in the browser. They are usually placed in the non-visible elements of a web page.
The Views are XForms controls for screen elements and can be placed directly in the visible section of web page. They are usually placed in the elements of a web page.
The model and views are bound together using reference or binding statements. These binding statements are used by the XForms dependency graph to ensure that the correct views are updated when data in the model changes. This means that forms developers do not need to be able to understand either the push or pull models of event processing.
All mouse events are processed by XForms controls and XML events are dispatched.
 Implementations of MVC as GUI frameworks
Smalltalk’s MVC implementation inspired many other GUI frameworks, such as the following:
* Cocoa framework and its GUI part AppKit, as a direct descendant of OpenStep, encourage the use of MVC. Interface Builder constructs Views, and connects them to Controllers via Outlets and Actions, although Cocoa tightly-couples the model to the view, effectively rendering it not an MVC pattern.
* GNUstep, also based on OpenStep, encourages MVC as well.
* Microsoft Foundation Class Library (MFC) – called the Document/View architecture
* Microsoft Composite UI Application Block, part of the Microsoft Enterprise Library.
* Qt since Qt4 release.
* Java Swing.
* Adobe Flex.
* Wavemaker open source, browser-based development tool based on MVC.
* Windows Presentation Foundation (WPF) uses a similar Model–view–viewmodel pattern.
* Visual FoxExpress is a Visual FoxPro MVC framework.
* Tk toolkit Tcl/Tk toolkit.