Model–view–controller

Model–view–controller
A general representation of the MVC design pattern.
Model-view-controller concept. The solid line represents a direct association, the dashed an indirect association (via an observer for example).

Model–view–controller (MVC) is a software architecture,[1] currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns).

Model View Controller (MVC) pattern creates applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.[2]

Contents

History

MVC was first described in 1979[3] 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".[4]

Overview

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, by pressing 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 an 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.)[5]
  4. A view queries the model in order to generate an appropriate user interface (for example the view lists the shopping cart's contents). The view gets its own data from the model. In some implementations, the controller may 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) that require a screen update.
  5. The user interface waits for further user interactions, which restarts the control flow 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.

The goal of MVC is, by decoupling models and views, to reduce the complexity in architectural design and to increase flexibility and maintainability of code. MVC has also been used to simplify the design of Autonomic and Self-Managed systems[6]

Concepts

The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.

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. A view port typically has a one to one correspondence with a display surface and knows how to render to it.

The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a view port to perform actions based on that input.

An MVC application may be a collection of model/view/controller triads, each responsible for a different UI element. The Swing GUI system, for example, models almost all interface components as individual MVC systems.

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, and which hand control to (X)HTML-generating components such as templating engines, XML pipelines, Ajax callbacks, etc.

The model is not necessarily merely a database; the 'model' in MVC is both the data and the business/domain logic needed to manipulate the data in the application. 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. Active Record is an accepted design pattern that merges domain logic and data access code — a model which knows how to persist itself.

Architecture vs. frameworks

Although MVC is typically associated with frameworks, it is essentially an architecture.[7] This means that it can be implemented even without an object-oriented language or a specific class hierarchy. For example, using as little as jQuery's trigger() and bind(), it is possible to build robust MVC applications in a browser using JavaScript. The key is simply to divide up the responsibilities of the MVC components into clearly defined sections of code. As stated in the overview, the code that embodies the model takes care of state, business logic, persistence, and notifications. The persistence can be implemented via cookies or AJAX. The notifications can be taken care of by the jQuery.trigger(). The code that embodies the view takes care of querying the model and rendering the view. The view code can be implemented in a variety of ways, including inserting HTML DOM nodes or changing CSS styles. The code that embodies the controller takes care of initialization of the model and wiring up the events between the view's HTML DOM elements and controller and between the model and the view code, using jQuery.bind().

Example

Here is a simple application of the pattern, implementing Java Servlets and Java Server Pages from Java EE:

Model
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).
View
The view is represented by a 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 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.

Implementations of MVC as GUI frameworks

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

Implementations of MVC as web-based frameworks

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

MVC is typically implemented as a "Model 2" architecture in Sun parlance. Model 2 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 "view for web" 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.[citation needed]

ABAP Objects

ActionScript

  • PureMVC Framework for ActionScript.
  • Cairngorm is a Flex Framework part of the Adobe Engagement Platform.
  • Fabrication Framework for ActionScript.
  • Robotlegs MVCS Framework for ActionScript with Dependency Injection.

C++

  • Wt - Web toolkit A library and application server for web applications using a desktop-like event-driven MVC pattern.
  • CppCMS - A C++ MVC framework that has taken many ideas from Django.
  • PureMVC A framework for C++.

CFML - Adobe ColdFusion, Railo, and Open BlueDragon

  • ColdBox Platform The first conventions over configuration framework and development platform for ColdFusion
  • ColdFusion on Wheels A convention over configuration framework similar to Ruby on Rails.
  • Framework One Framework/1 is a new framework developed by Sean Corfield and provides a good stepping stone for users new to the MVC pattern. It consists of a single CFC and favors convention over configuration.
  • 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.
  • 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.
  • PureMVC Framework for ColdFusion.

MS-DOS

  • DOS on Dope [8]

Flex

  • Cairngorm one of the primary open source frameworks for application architecture in Adobe Flex.
  • PureMVC ActionScript 3 MVC framework for Flex, Flash and AIR

Groovy

Java

MVC web application frameworks:

Java Stand-alone Application Toolkit:

  • Swing, which uses a Model-Delegator pattern, where the view and controller are combined, but the model is separate.
  • ZK - an Ajax framework that enables the Ajax-level MVC pattern.

JavaScript

MVC web application frameworks:

  • Knockout.js An MVC Framework based on MVVM for JavaScript.
  • SproutCore
  • PureMVC Framework for JavaScript
  • JavascriptMVC JavaScript MVC framework based upon jQuery core.
  • eMVC is an MVC framework based upon Dojo Toolkit.
  • Dojo toolkit MVC used in stores + widgets.
  • Backbone.js A light weight MVC Framework for JavaScript.
  • ExtJS uses MVC as of version 4
  • YUI 3 has an MVC module
  • AngularJS
  • eyeballs.js

Informix 4GL

  • EGL — IBM's EGL MVC Implementation

.NET

Perl

PHP

  • Agavi is a PHP5 application framework that focuses on sustained quality and correctness.
  • Alloy A lightweight REST-focused modular Hierarchical MVC PHP 5.3 framework.
  • AppFlower is a Rapid Application Development framework based on MVC, PHP5 and Symfony.
  • CakePHP A web application framework modeled after the concepts of Ruby on Rails.
  • CodeCharge Studio is a visual rapid application development environment for web-based database driven application development. Code Charge Studio places emphasis on code generation technology to provide ASP.NET, PHP, JSP, Servlets, ColdFusion and Perl language support.
  • AN Framework ANFire is a PHP framework that make it easy to develop build dynamic websites, web applications, and what you need in PHP, JS. (Website)
  • CodeIgniter A simple, light, fast, open source MVC framework for building websites using PHP.
  • DooPHP Doo framework is one of the fastest, if not the fastest PHP framework available.
  • Exponent CMS A Content Management System web application framework using its own MVC framework modeled after Rails.
  • eZ Publish Based on eZ Components is an object-oriented web application framework written in PHP that separates its functionality into several abstraction layers, following a strict MVC approach.
  • Feng Office is an open source MVC Framework Extranet that allows a group of a geographically distributed people to collaborate by sharing information over the Internet.
  • FLOW3 A modern PHP framework (Website)
  • Fuel is a modern open source MVC framework, using PHP5.3, combining the best of CodeIgniter, Kohana, Rails & more.
  • Kohana Framework v2.x is an open source MVC framework, while v3.x is HMVC (both supported).
  • Nette Very powerful PHP framework with very good performance.[citation needed]
  • Odin Assemble A PHP-based MVC framework with a small footprint.
  • phpXCore An MVC design pattern based PHP content management framework compatible with PHP4 and PHP5.
  • PureMVC A framework for PHP.
  • Horde Framework A framework and application suite for PHP
  • Qcodo An open-source PHP 5 web application framework.
  • SleekMVC A fast and lightweight PHP 5 MVC framework, featuring similar syntax to Kohana.
  • Scriptcase Generator A powerful tool to increase web development productivity.
  • SilverStripe A developer friendly CMS with it's own Framework. Use the framework with or without the CMS. (Website)
  • Switch board (framework) A PHP 5 MVC framework with routing.
  • SIFO MVC PHP Framework with multiple DB support, Sphinx, Redis and other stuff.
  • Symfony Framework A PHP 5 MVC framework modeled after the concepts of Ruby on Rails.
  • Yii An open source, object-oriented, high-performance component-based PHP web application framework.
  • ZanPHP ZanPHP is an agile Web application development framework written in PHP5 that uses different design patterns and best practices to create applications more quickly with good quality code.
  • Zend Framework An open-source PHP 5-based framework featuring a MVC layer and a broad-spectrum of loosely coupled components.
  • Lightwieght_MVC LightWeight MVC is a Open-Source GPL/Lesser GPL PHP5 Framework that is built to teach users the basics of MVC and implementation of a MVC Powered Web Site.

Python

  • Django A complete Python web application framework. Django prefers to call its MVC implementation MTV, for model-template-view.[10]
  • Enthought The Enthought Tool Suite brings the Model–view–controller mindset to scientific GUIs and visualization
  • Pylons Python Web Framework
  • TurboGears for Python
  • web2py An open-source web application framework focussed on rapid development
  • Zope Web application server
  • Plone Content management system built on top of Zope
  • PureMVC Framework for Python

Ruby

Smalltalk

XML

  • XForms—XForms has an integrated Model–view–controller architecture with an integral dependency graph that frees the programmer from specifically having to perform either push or pull operations.
  • XRX-XForms, ReST, XQuery-is a web application framework where server logic is written in XQuery which processes the submitted XForm, and (typically) returns another (often generated on-the-fly) XForm to the client.

See also

References

  1. ^ Reenskaug, Trygve. "MVC XEROX PARC 1978-79". http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html. Retrieved 2008-06-09. 
  2. ^ Model View Controller aspnet4.com
  3. ^ Trygve M. H. Reenskaug/MVC—XEROX PARC 1978-79
  4. ^ How to use Model–View–Controller (MVC)
  5. ^ Complex controllers are often structured using the command pattern to encapsulate actions and simplify extension.
  6. ^ E. Curry and P. Grace, “Flexible Self-Management Using the Model-View-Controller Pattern,” IEEE Software, vol. 25, no. 3, pp. 84-90, May. 2008.
  7. ^ Sagar Vasekar; Michael Rimov; Larry Hamel; et. al. (2004-12). "Expresso Developer's Guide" (in English) (HTML). http://www.jcorporate.com/expresso/doc/edg/edg_WhatIsMVC.html: Jcorporate. "Flexibility in large component based systems raise questions on how to organize a project for easy development and maintenance while protecting your data and reputation, especially from new developers and unwitting users. The answer is in using the Model, View, Control (MVC) architecture." 
  8. ^ http://dod.codeplex.com/
  9. ^ "Product Review: WaveMaker’s point-and-click Java". Infoworld. April 24, 2008. http://www.infoworld.com/article/08/04/17/16TC-wavemaker-studio_1.html. Retrieved 2008-04-25. 
  10. ^ 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?, FAQ: General, Django

External links


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 — (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 …   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”