Model view controller

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
m (Reverted edits by Ebybymic (Talk); changed back to last version by Marina)
 
(3 intermediate revisions by 2 users not shown)
Line 28: Line 28:
 
This is the pattern that the developers of Apple's Cocoa framework believe is MVC, they even made a [http://youtube.com/watch?v=YYvOGPMLVDo song] about it.
 
This is the pattern that the developers of Apple's Cocoa framework believe is MVC, they even made a [http://youtube.com/watch?v=YYvOGPMLVDo song] about it.
 
* '''Controller''' resembles the [[Mediator]] between '''Model''' and '''View'''
 
* '''Controller''' resembles the [[Mediator]] between '''Model''' and '''View'''
* The purpose of the Controller, in this case, is to ensure smooth communication and validation between the Model and View.
+
* The purpose of the Controller, in this case, is to ensure smooth communication and validation between the '''Model''' and '''View'''. The controller takes user input, manupulates the '''Model''' and gets '''View''' to update appropriately.
 +
* The '''View''' represents the display of the model in the UI.
  
 
=== MVC as an Input-Output Process ===
 
=== MVC as an Input-Output Process ===

Latest revision as of 03:17, 25 November 2010

The Model View Controller (MVC) is one of the oldest architectural patterns. It is still widely used in web and application programming. It was initially developed by Trygve Reenskaug in 1979. In order to complete this pattern, he utilised his knowledge of control and command strategies and the practices of Norwegian shipping yards.

The general premise is to separate an application or architectural area into three distinct parts:

  • Model: This is usually considered to be related to a domain model of the application, possibly including persistence. It will often include behaviour as well as data.
  • View: The interface with the web client/browser or the application's GUI. This part may also be used to provide internal details to other parts of the program and does not need to be directly related to the end user.
  • Controller: This is the most disputed component, it can either act as a Mediator, Strategy or business logic.

While the components are relatively undisputed, the connections between them are more important and more conflicting. Below the known varieties of the MVC pattern are described. Controversy exists on whether the MVC should be considered an OO design pattern at all.

An important source of discussion and debate on this pattern is Ward's wiki, and this information can be found here.

Contents

Usage

Given the variety of patterns with the name 'MVC', it would seem that the term has lost explanatory potential. Maybe the term should be avoided to limit misunderstanding.

Purpose

Each of the different patterns that can be thought of as MVC have subtly different effects and purpose.

Patterns

So, lets consider the variations of MVC.

MVC-Observer-Strategy

Diagram from lecture 27/7/09

This version is the original MVC pattern proposed by Trygve Reenskaug in 1979 and popularised with its use with Smalltalk. It is also Sun's proposed structure of MVC in J2EE.

MVC-Mediator

Diagram from lecture 27/7/09

This is the pattern that the developers of Apple's Cocoa framework believe is MVC, they even made a song about it.

  • Controller resembles the Mediator between Model and View
  • The purpose of the Controller, in this case, is to ensure smooth communication and validation between the Model and View. The controller takes user input, manupulates the Model and gets View to update appropriately.
  • The View represents the display of the model in the UI.

MVC as an Input-Output Process

Diagram from lecture 27/7/09

The diagram above shows how MVC can be viewed as a slight deviation from the OO paradigm. This is one way to argue that MVC is not OO [1].

MVC as a Distributed Architecture

Distributed MVC

This pattern is often used by those in web application development and is often know as MVC.

  • View: The graphics/markup coding that provides a user interface to a remote user (i.e. in a web browser)
  • Controller: The systems business logic. A distinct layer between the Model and the View. Provides a handling of user state, if necessary, and any behavioural modifications required to the persistent model.
  • Model: A set of data objects that are responsible for the underlying persistence of a system. Usually these classes form the interface to an underlying DB.

Each of these layers has the potential to be separated in a physical (and logical) fashion. Multiple versions of each layer can run on different machines with heartbeats between allowing the state to be maintained yet providing redundancy and the possibility of large scale usage.

MVC as a Round Trip Pattern

This version of the pattern calls for a distinct separation of the three elements in a round trip manner.

  • View: Displays information to the user. Updates to the view directly update the model.
  • Controller: Controls the information sent to the user by manipulating the view.
  • Model: The model provides the underlying domain structure. It tells the controller when and how it changes.

External links

See also

Personal tools