Everything about Model-view-controller totally explained
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's 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 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.
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 popular and widely used.
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 (for example, 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 doesn't specifically mention the data access layer because it's 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 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 (for example 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. (for example controller updates user's Shopping cart).
- A view uses the model (indirectly) to generate an appropriate user interface (for example 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.
By decoupling models and views, MVC helps to reduce the complexity in architectural design, and to increase flexibility and reuse.
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's 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)
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).
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
Microsoft Foundation Classes (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 Toolkit since Qt4 Release.
Java Swing
Windows Presentation Foundation (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 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.
ASP
ASP Xtreme Evolution - A VBScript ASP 3.0 MVC Framework
Troika.ASP - A JScript ASP 3.0 MVC Framework
.NET
ASP.NET MVC Framework (MVC home on the ASP.NET web site
)
Igloo software (Experimental) MVC Framework for .NET 2.0
Maverick.NET
Microsoft UIP
Monorail An ActionPack inspired MVC framework from the Castle Project
PureMVC Framework for C#
Supports .NET, Windows Mobile, Pocket PC, and Silverlight development platforms
Web Client Software Factory
MVC# Framework
Actually is a Model View Presenter framework. But as such has much in common with MVC.
NMVP
ActionScript
ARP
Usable with AIR, Flex, and Flash
Cairngorm Usable with AIR, and Flex
PureMVC Framework for AS2
Supports Flash and FlashLite platforms
PureMVC Framework for AS3
Supports Flex, Flash and AIR platforms
ColdBox
Fusebox
Mach-II A framework that focuses on trying to ease software development and maintenance
Model-Glue
PureMVC Framework for ColdFusion
Erlang
ErlyWeb
Java
MVC web application frameworks:
Aranea
Cocoon
Grails
Oracle Application Framework
PureMVC Framework for Java
Supports J2EE, J2SE, J2ME, and JavaFX development platforms
Spring MVC Framework
Struts
Tapestry
WebObjects
WebWork
Wicket
JSF
SAP Web Dynpro
JavaScript
CJAX
A PHP-Javascript development tool for AJAX
Archetype
Javascript Framework for structuring and ease development of RIA.
JavaScript MVC
An open-source JavaScript framework for developing web applications.
Junction
A Ruby on Rails port to Javascript.
Jamal
A Javascript framework built on top of jQuery.
Informix 4GL
Informix 4GL MVC models to use for Informix 4GL report and form creation
EGL – IBM's EGL MVC Implementation
Object-Pascal
Powtils
Ongoing development on a new MVC library for web programming with Object-Pascal (FreePascal, Delphi etc).
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
OpenInteract2
is a web application server written in Perl. It features integrated data persistence, security, user and group management, plus an easy way to create and distribute fully database-independent applications.
PageKit
A mod_perl based web application framework that uses a template system and XML.
PHP
Agavi
an open-source, LGPL licensed MVC framework for creating applications written using PHP5.
AGLite Framework
Simple, easy and flexible framework for PHP.
Akelos PHP Framework a Ruby on Rails port to PHP4/5.
BareBonesMVC
A one-file, no-configuration, MVC framework for PHP5.
CakePHP webapplication framework modeled after the concepts of Ruby on Rails.
CodeIgniter A PHP MVC framework.
DragonPHP
MVC2 Framework for PHP 5.
FLOW3
A PHP5 / PHP6 based enterprise application framework, with MVC, Dependency Injection, Aspect-Oriented Programming and more.
FUSE A powerful but easy-to-use PHP 5 Framework for MVC development
Fusebox
Framework for building ColdFusion and PHP web applications.
Jelix Framework an open source PHP 5 MVC framework designed for highly performance.
KohanaPHP A powerful, lightweight, easily extendable PHP 5 MVC Framework.
Kumbia Framework
Simple, easy and flexible framework for PHP.
LightVC
Lightweight PHP 5 Strict MVC Framework with decoupling of Model and other non-View-Controller essentials to promote code reuse.
Lion Framework
An open-source PHP 5 framework with a push & pull MVC implementation
MicMVC
A simple framework for creating standalone MVC websites in PHP5 with RoR style models.
Odin Assemble Small footprint PHP based MVC Framework.
OnPHP
onPHP is the mature GPL'ed multi-purpose object-oriented PHP framework (plus c-module)
PHP on Trax
Strictly follows Ruby on Rails syntax and functionality but written in php5. Originally called PHP on Rails
.
phpHtmlLib
MVC based OO framework compatible with PHP4 and PHP5 licensed under GNU LGPL.
phpXCore A MVC design pattern based PHP content management framework compatible with PHP4 and PHP5.
PRADO A PHP 5 MVC framework.
PureMVC Framework for PHP
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.
Solar PHP 5 framework
Solar is a PHP 5 framework for rapid application development. It is fully name-spaced and uses enterprise application design patterns, with built-in support for localization and configuration at all levels.
Switch board with Routing PHP 5 MVC Framework with Routing.
Symfony Framework PHP 5 MVC Framework.
TinyMVC Framework
Simple and lightweight PHP5 MVC (Model-View-Controller) framework.
TYPO3 extension library lib/div
PHP 4/5 MVC framework for TYPO3 extension development
XPT Framework
A PHP 5 MVC framework.
Zend Framework A PHP 5-based MVC framework.
ZNF PHP5 MVC framework for enterprise web applications
Zoop Framework A Mature PHP 4/5 MVC framework.
A PHP OpenSource CMS
Python
Django A complete Python web application framework. Django prefers to call its MVC implementation MTV, for Model-Template-View (External Link
).
PureMVC Framework for Python
Pylons - Python Web Framework
Spring Python
TurboGears for Python
web2py
A full-stack python web application framework
Zope Content Management Framework
Ruby
Camping
Merb
Nitro
Ramaze
Ruby on RailsFurther Information
Get more info on 'Model-view-controller'.
|
External Link Exchanges
Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:
<a href="http://model-view-controller.totallyexplained.com">Model-view-controller Totally Explained</a>
Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned. |