Information About

Model-view-controller




).]]

Model-view-controller ('''MVC''') is an Architectural Pattern used in Software Engineering . In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and User Interface (view) concerns, so that changes to the
user interface will not affect data handling, and that the data can be reorganized without changing the user
interface. The model-view-controller solves this problem by decoupling data access and Business Logic from Data Presentation and user interaction, by introducing an intermediate component: the controller.


HISTORY


The pattern was first described in 1979http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html by Trygve Reenskaug , then working on Smalltalk at Xerox research labs. The original implementation is described in depth in the influential paper ''Applications Programming in Smalltalk-80(TM):How to use Model-View-Controller''http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html.


PATTERN DESCRIPTION

It is common to split an application into separate layers: presentation (UI), domain logic, and data access. In MVC the presentation layer is further separated into View and Controller . MVC encompasses more of the architecture of an application than is typical for a design pattern.

;Model
: The domain-specific representation of the information on which the application operates. Domain logic adds meaning to raw data (e.g., calculating if today is the user's birthday, or the totals, taxes and shipping charges for shopping cart items).
: 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.
;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.
;Controller
: Processes and responds to events, typically user actions, and may invoke changes on the model.

MVC is often seen in Web Application s, where the view is the actual HTML page, and the controller is the code that gathers dynamic data and generates the content within the HTML. Finally the model is represented by the actual content, usually stored in a Database or XML files.

Though MVC comes in different flavors, control flow generally works as follows:
# The user interacts with the user interface in some way (''e.g.'', presses a button).
# A controller handles the input event from the User Interface , often via a registered Handler or Callback .
# The controller accesses the model, possibly updating it in a way appropriate to the user's action (e.g., controller updates user's Shopping Cart ).Complex controllers are often structured using the Command Pattern to encapsulate actions and simplify extension.
# A view uses the model to generate an appropriate user interface (''e.g.'', the view produces a screen listing the shopping cart contents). The view gets its own data from the model. The model has no direct knowledge of the view.
# The user interface waits for further user interactions, which begins the cycle anew.

In conclusion, by decoupling models and views, MVC helps to reduce the complexity in architectural design, and to increase flexibility and reuse.


EXEMPLARY MVC CONCEPTIONS OF SELECTED LANGUAGES



GUI frameworks



Java: Java Swing

Java Swing is different from the other frameworks, in that it supports two MVC patterns.

;Model (Frame level)
:Like the other frameworks, the design of the real model is usually left to the developer.

;Model (Control level)
:Swing also supports models on the control level. Unlike other frameworks, Swing exposes the internal storage of each control as a model.

;View
:The view is represented by a class that inherits from Component.

;Controller
:Java Swing doesn't necessarily use a single controller. Because its event model is based on interfaces, it is common to create an anonymous action class for each event. In fact, the real controller is in a separate Thread . It catches and propagates the events to the view and model.


Web frameworks



.NET: ASP.NET


In ASP.NET , the patterns for the view and controller are not well defined. The model is left to the developer to design, views and controls can be created in a variety of ways.

;Model
:DataSets are the most common use of the model in .NET projects. A typed DataSet allows one to create an entity specific model.

;View
: The ASPX and ASCX files generally handle the responsibilities of the view, although it can also come from compiled server controls. With this pattern, the view object inherits from the controller object. This is different from the Smalltalk implementation, in which separate classes have pointers to one another.

;Controllers
:The duties of the controller are split between two places. The generation and passing of events is part of the framework and more specifically the Page and Control classes. The handling of events is usually done in the '' Code-behind '' class. However, moving code specific to the transition between views in a separate Controller is a good practice. In turn, it becomes possible to centralize the registration of Observers in the isolated Controller.


.NET: Windows Forms


In WinForms , a .NET framework, the patterns for the view and controller are well defined. The model is left to the developer to design.

;Model
:Just like ASP.Net, WinForms does not strictly require a model. The developer has the option to create a model class, but may choose to forget it and have the event handlers in the controller perform any calculations and data persistence. Again, using a model to encapsulate business rules and database access is both possible and preferable. It is left to developers to design the Model.

;View
:A class inheriting from either Form or Control handles the responsibilities of the view. In the case of WinForms, the View and Controller are compiled into the same class. This differs from ASP.Net, which uses inheritance, and Smalltalk, which have separate classes with pointers to one another.

;Controller
:The duties of the controller are split between three places. The generation and passing of events starts at the OS level. Inside the .Net framework, the Form and Control classes route the event to the proper event handler. The handling of events is usually done in the Code-behind class how it can be changed.


Combined frameworks



Java: Java Enterprise Edition (Java EE)


Unlike the other frameworks, Java EE defines a pattern for model objects.

;Model
:The model is commonly represented by Entity Bean s, although the model can be created by a Servlet using a business object framework such as Spring .

;View
:The view in a Java EE application may be represented by a Java Server Page ,which may be currently implemented using JavaServer Faces Technology(JSF). Alternately, the code to generate the view may be part of a servlet.

;Controller
:The controller in a Java EE application may be represented by a servlet.


IMPLEMENTATIONS OF MVC AS GUI FRAMEWORKS


Smalltalk's MVC implementation inspired many other GUI frameworks such as:



IMPLEMENTATIONS OF MVC AS WEB BASED FRAMEWORKS

In the design of web applications, MVC is implemented by Web Template System s as "View for web" component.

MVC is also known as a " Model 2 " architecture in Sun parlance. Complex web applications continue to be more difficult to design than traditional applications, and MVC is being pushed as a potential solution to these difficulties.


ActionScript

  • ARP Usable with AIR, Flex, and Flash

  • Cairngorm Usable with AIR, Flex, and Flash

  • PureMVC Suitable for use with AIR, Flex, Flash, and any platform running AS3 (no non-native class dependencies)

  • as2mvc an MVC framework for ActionScript 2



Java

MVC web application frameworks:


JavaScript

  • AJILE Cross-browser compatible (ECMAScript-262, edition 3, JavaScript 1.3+, JScript 3.0+)



Perl

  • Catalyst An MVC-based avant-garde web framework.

  • CGI::Application A mature, lightweight, flexible MVC framework for web application development.

  • Gantry Framework A web application framework for Apache/mod_perl, CGI and Fast-CGI.

  • Jifty A full-stack application framework.

  • Maypole A Perl framework for MVC-oriented web applications, similar to Jakarta's Struts



PHP



Python

  • Django A complete Python web application framework.

  • Notably, Django prefers to call its MVC implementation MTV, for Model-Template-View .



Ruby



.NET



Other languages

''Please remove those languages, that are already listed above. Then remove this line.''


SEE ALSO



REFERENCES



EXTERNAL LINKS


General information regarding MVC

Specific aspects of MVC or alternatives to MVC