Model-view-controller


Model-view-controller

Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the "model" represents the information (the data) of the application and the business rules used to manipulate the data; the "view" corresponds to elements of the user interface such as text, checkbox items, and so forth; and the "controller" manages details involving the communication to the model of user actions such as keystrokes and mouse movements.

History

The pattern was first described in 1979 [http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html] 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". [ [http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html How to use Model-View-Controller (MVC) ] ]

After that numerous derivatives of the MVC pattern appeared. Probably one of the most known of them is the Model View Presenter pattern, which appeared in the early 90s and was designed to be an evolution of MVC. However Model-View-Controller still remains very widely used.

Pattern description

Model-view-controller is both an architectural pattern and a design pattern, depending on where it is used.

As an architectural pattern

It is common to split an application into separate layers that run on different computers: presentation (UI), domain logic, and data access. In MVC the presentation layer is further separated into view and controller.

MVC is often seen in web applications, 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 in XML nodes, and the business rules that transform that content based on user actions.

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 notifies the model of the user action, possibly resulting in a change in the model's state. (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 (indirectly) 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.

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.

As a design pattern

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

Selected frameworks

GUI frameworks

Java: Java Swing

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

Model: Frame level model-- Like other frameworks, the design of the real model is usually left to the developer.: Control level model-- Swing also supports models on the level of controls (elements of the graphical user interface). 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 (the Event dispatching thread). It catches and propagates the events to the view and model.

Combined frameworks

Java: Java Enterprise Edition (Java EE)

Simple Version using just Servlets and JSPs from J2EE:

;Model:The model is a collection of java classes that together do something useful - they make up a software application which might involve moving data around. There is a single front end class that can communicate with any UI - eg a console, a thick GUI or a web application.

;View:The view is represented by Java Server Page, with data being transported to the page in the HttpServletRequest or HttpSession.

;Controller: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 simple version uses the best parts of Servlet and JSP technology: the servlet is essentially a Java class and communicates and interacts with the model but does not have to do extensive generation of xhtml output; the JSPs do not have to communicate with the model as they are provided with the information they need by the servlet - they can concentrate on creating xhtml output.

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

;Model: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.

;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). Alternatively, 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, which may be currently implemented using JavaServer Faces (JSF).

XForms

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.

;ModelXForms stores the Model as XML in the browser.

;ViewThe Views are XForms controls for screen elements and can be placed directly in a web page.

The model and views are bound together using reference or binding statements. These binding statements are used by the XForms dependancy graph to ensure that the correct views are updated when data in the model changes.

;ControllerAll 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:

*Core Data framework in Mac OS X, a modern addition to Cocoa.
*GNUstep, based on these technologies, also use MVC.
*GTK+
*JFace
*MFC (called Document/View architecture here)
*Nextstep development environments encourage the use of MVC. Cocoa
*OpenStep development environments encourage the use of MVC. Cocoa
*Qt since Qt4 Release.
*Java Swing
*Adobe Flex
*Wavemaker open source, browser-based development tool based on MVC
*WPF uses a similar Model-view-viewmodel pattern.
*Visual FoxExpress is a Visual FoxPro MVC framework.

Implementations of MVC as web-based frameworks

In the design of web applications, MVC is implemented by web template systems as "View for web" component.

MVC is typically implemented as a "Model 2" architecture in Sun parlance. Model2 focuses on efficiently handling and dispatching full page form posts and reconstructing the full page via a front controller. Complex web applications continue to be more difficult to design than traditional applications because of this "full page" effect. More recently AJAX driven frameworks that focus on firing focused UI events at specific UI Components on the page are emerging. This is causing MVC to be revisited for web application development using traditional desktop programming techniques.

.NET

*ASP.NET MVC Framework
*Maverick.NET
*Monorail An ActionPack inspired MVC framework from the Castle Project
*ProMesh.NET Open source MVC Web Application Framework for .NET 2.0 or higher.

ColdFusion

*Mach-II A framework that focuses on trying to ease software development and maintenance
*Model-Glue Through a simple implementation of Implicit Invocation and Model-View-Controller, they allow applications to be well organized without sacrificing flexibility.
*FuseBox Fusebox does not force the Model-View-Controller (MVC) pattern or Object-Oriented Programming (OOP) on the developer. However, either or both of these development approaches can be used with Fusebox.

Java

MVC web application frameworks:
* Aranea
* Cocoon
* Grails
* Google Web Toolkit
* Oracle Application Framework
* Spring MVC Framework
* Struts
* Stripes
* Tapestry
* WebObjects
* WebWork
* Wicket
* JSF

JavaScript

MVC web application frameworks:
* SproutCore
* Wavemaker WYSIWYG development platform for Ajax web applications [cite web
url = http://www.infoworld.com/article/08/04/17/16TC-wavemaker-studio_1.html
title = Product Review: WaveMaker’s point-and-click Java
publisher = Infoworld
date = April 24, 2008
accessdate = 2008-04-25
]
* DojoMVC JavaScript MVC based upon Dojo core. Includes jQuery integration.

ABAP Objects

* BSP
* Web Dynpro ABAP

Informix 4GL

*Informix 4GL MVC models to use for Informix 4GL report and form creation
*EGL – IBM's EGL MVC Implementation

Perl

*Catalyst An MVC-based avant-garde web framework.
*Maypole A useful perl MVC framework
*Gantry An MVC framework similar to django
*Jifty the "one true way" for MVC
* Another MVC Web Framework
* MVC Framework
*Solstice Based on the MVC programming paradigm,

PHP

*Akelos PHP Framework a Ruby on Rails port to PHP4/5.
*barebonesmvc A one-file, no-configuration, PHP 5 MVC framework.
*CakePHP webapplication framework modeled after the concepts of Ruby on Rails.
*CodeIgniter A PHP MVC framework.
*ash.MVC A Simple MVC Framework with PHP.
*FUSE A powerful but easy-to-use PHP 5 Framework for MVC development modeled after the concepts of Ruby on Rails.
*Jelix Framework an open source PHP 5 MVC framework designed for highly performance.
*Joomla v1.5.x is an open source Content Management System that employs the MVC model for its extensions, called components and modules.
*KISSMVC Feather-weight, procedural PHP MVC Framework designed based on the KISS Principle.
*KohanaPHP A powerful, lightweight, easily extendable PHP 5 MVC Framework.
*Konstrukt A PHP MVC / RESTful framework
*LightVC Lightweight PHP 5 Strict MVC Framework with decoupling of Model and other non-View-Controller essentials to promote code reuse.
*Odin Assemble Small footprint PHP based MVC Framework.
*Orinoco Framework is a full-stack yet lightweight framework written in PHP5. It implements the Model 2 design paradigm.
*phpXCore A MVC design pattern based PHP content management framework compatible with PHP4 and PHP5.
*PRADO A PHP 5 MVC framework modeled after ASP.NET web forms.
*Qcodo is an open-source PHP 5 web application framework
*SilverStripe contains a fully fledged PHP 5.2 ORM/MVC Framework focused on building websites. Much like Ruby on Rails.
*Solar
*Switch board (framework) with Routing PHP 5 MVC Framework with Routing.
*Symfony Framework PHP 5 MVC Framework modeled after the concepts of Ruby on Rails.
*XPT Framework A PHP 5 MVC framework.
*Zend Framework A PHP 5-based MVC framework modeled after the concepts of Ruby on Rails.
*ZNF PHP5 MVC framework for enterprise web applications
*Zoop Framework A Mature PHP 4/5 MVC framework.
*Zigmoyd PHP 4/5 MVC Framework

Python

*Django A complete Python web application framework. Django prefers to call its MVC implementation MTV, for Model-Template-View.
*Pylons - Python Web Framework
*TurboGears for Python
*web2py Web Framework
* Zope Content Management Framework

Ruby

*Camping
*Merb
*Nitro
*Ramaze
*Ruby on Rails

malltalk

*AIDA/Web

XML

*XForms

ee also

*Trygve Reenskaug - first formulated the model-view-controller pattern
*Architectural patterns
*Model View Presenter
*Model 1
*Three-tier (computing)
*The Observer design pattern
*The Template Method design pattern
*The Presentation-abstraction-control (PAC) pattern
*The naked objects pattern, often positioned as the antithesis of MVC, though Reenskaug suggests otherwise
*Model View Adapter

References

External links

General information regarding MVC
* [http://java.sun.com/blueprints/patterns/MVC.html An overview of the MVC pattern in Java from the Sun website]
* [http://www.codeproject.com/aspnet/ModelViewPresenter.asp Model View Presenter with ASP.NET] CodeProject article.
* [http://www.martinfowler.com/eaaDev/uiArchs.html History of the evolution of MVC and derivatives] by Martin Fowler.
* [http://www.ash-mvc.org/website/framework/framework.html MVC Framework with PHP]
* [http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx ASP.NET MVC Framework] Microsoft's Scott Guthrie on .NET MVC
* [http://download.microsoft.com/download/f/e/b/febedc0c-dd47-4062-ad53-40e34d556a5d/ScottHanselmanIntroToMVC.wmv Introduction to the ASP.NET Model View Controller (MVC) Framework] Scott Hanselman builds an application step-by-step using the first CTP of the ASP.NET MVC Framework in this Introductory Video
*cite news | last=Holub | first=Allen | title=Building user interfaces for object-oriented systems | date=1999 | publisher=Java World | url=http://www.javaworld.com/javaworld/jw-07-1999/jw-07-toolbox.html
*Greer, Derek. " [http://ctrl-shift-b.blogspot.com/2007/08/interactive-application-architecture.html Interactive Application Architecture Patterns] ", Ctrl-Shift-B, 2007.
* [http://pclc.pace.edu/~bergin/mvc/mvcgui.html Building Graphical User Interfaces with the MVC Pattern in Java]
* [http://dev.oathouse.com/perfectServlet See oathouse.com's example with source code and demonstration]


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Model View Controller — Konzept. Hinweis: die durchgezogene Linie symbolisiert eine direkte Assoziation, die gestrichelte eine indirekte Assoziation (zum Beispiel über einen Beobachter). Model View Controller (englisch  model view controller (MVC), deutsch auch: M …   Deutsch Wikipedia

  • Model–view–controller — A general representation of the MVC design pattern. Model view controller concept. The solid line represents a direct as …   Wikipedia

  • Model-View-Controller — Шаблон проектирования Model View Controller Кон …   Википедия

  • Model View Controller — Modèle Vue Contrôleur Pour les articles homonymes, voir MVC. Le schéma de cette figure résume les différentes interactions entre le modèle, la vue et le contrôleur. Les lignes pleines indiquent une ass …   Wikipédia en Français

  • Model-view-controller — …   Википедия

  • Hierarchical Model View Controller — Основная статья: Model View Controller Выделяют два варианта таких иерархических паттернов – это Hierarchical Model View Controller (HMVC) и Presentation Abstraction Control (PAC), который пришёл из мира Java. Отличие заключается в том, что HMVC… …   Википедия

  • Model–view–adapter — (MVA) or mediating controller MVC is an architectural pattern and multitier architecture, used in software engineering. In complex computer applications that present large amounts of data to users, developers often wish to separate data (model)… …   Wikipedia

  • Model View Presenter — (Abkürzung: MVP; wörtlich etwa ‚Modell Ansicht Präsentator‘) ist ein Entwurfsmuster in der Softwareentwicklung, das aus dem Model View Controller (Abkürzung: MVC) hervorgegangen ist. Es beschreibt einen neuartigen Ansatz, um das Modell (engl.… …   Deutsch Wikipedia

  • Model View Presenter — is a software pattern considered as a derivative of the Model view controller. Pattern description The View is defined as an interface that the Presenter will use for getting and setting data to and from the Model. The View implementation will… …   Wikipedia

  • Model–view–presenter — (MVP) is a derivative of the model–view–controller (MVC) software pattern, also used mostly for building user interfaces. In MVP the presenter assumes the functionality of the middle man (played by the controller in MVC). Additionally, the view… …   Wikipedia


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.