A European Informational Website
learn more
Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present lots of data to the user, one often wishes to separate data (model) and user interface (view) concerns, so that changes to the user interface do not affect the 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.
It is common to split an application into separate layers: presentation (UI), domain, 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.
The domain-specific representation of the information on which the application operates. It is a common misconception that the model is another name for the domain layer. 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.
Renders the model into a form suitable for interaction, typically a user interface element.
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 code which gathers dynamic data and generates the content within the HTML is the controller. 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 pattern was first described in 1979[2] 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[3].
Smalltalk's MVC implementation inspired many other GUI frameworks such as:
TROIKA.ASP Framework is Model-View-Controller (Model 2) web development framework for ASP 3.0. It uses OO JavaScript for Model and Controller logic and XSLT transformation templates for the View.
Probably the first "Proper" MVC framework for ASP 3.0!
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.
DataSets are the most common use of the model in .Net projects. A typed DataSet allows one to create an entity specific model.
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.
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.
In WinForms, a .NET framework, the patterns for the view and controller are well defined. The model is left to the developer to design.
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
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.
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.
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 Java Server Page. Alternately, 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.
Java Swing is different from the other frameworks, in that it supports two MVC patterns.
Like the other frameworks, the design of the real model is usually left to the developer.
Swing also supports models on the control level. Unlike other frameworks, Swing exposes the internal storage of each control as a model.
The view is represented by a class that inherits from Component.
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.
The Nitro and Ruby on Rails web frameworks are popular Model-view-controller architectures for Ruby.
Python has many MVC frameworks. The two most popular frameworks are Django and TurboGears.
The most popular MVC for Perl is Catalyst. Catalyst borrows from other frameworks such as Ruby on Rails and Apache Struts. It makes extensive use of the CPAN archive to provide the various components as follows.
Catalyst is very flexible on the Model, examples being DBIx::Class, Class::DBI, Class::DBI::SQLite
CPAN modules such as Template Toolkit, Mason, HTML::Template, XSLT and Petal can all be used as the View.
Catalyst uses advanced URL to action dispatching to map the URL to the correct controller.
There are many different MVC frameworks for PHP, some of which seek to imitate framework features from Java, .NET, and elsewhere. PHP Frameworks like CakePHP, Symfony, PHPOnTrax and Code Igniter implement the MVC pattern. Often the Smarty template language is used to separate presentation from program logic. Zend, the primary company behind the development of PHP, recently began developing an MVC framework for PHP. Symfony, cakePHP or Achievo ATK are newer rapid/development MVC frameworks that mimic some of the best features on Rails and Django. Joomla version 1.5 uses an MVC model throughout its web-application framework.
PHP is the most popular language for creating Content Management Systems and some of the CMSs implement MVC. The popular Drupal CMS is an example of optional MVC. The core system separates the data, processes, and presentation but still lets users create shortcuts to the data when developing new features. Optional MVC provides the advantages of MVC while allowing developers to plug in external modules that are not yet MVC.
ColdFusion also does not have a built in MVC structure, but has many third-party frameworks such as Model-Glue, Fusebox and Mach-II which stress the MVC ideal
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.
General information regarding MVC
Specific aspects of MVC or alternatives to MVC
Contents