MVC: Model-View-Controller Design Pattern used in Struts, Ruby on Rails, etc

70

By learnprogramming

The Original MVC from Reenskaug of Xerox Parc

Model-View-Controller (MVC) is a classic design pattern originally crafted by Reenskaug at Xerox Parc and implemented later on the Smalltalk Language. It was originally called Thing-Model-View-Editor in a first paper before being called Model-View-Controller in a second paper where Model, View and Controller are defined:

  • Model: a human construct that abstracts a real world system to help us better understand them. There are many ways to do so depending on the purposes of the model. In a software, the model is the object that represents the data. The model manages the data and conducts all transformations on that data.
  • View: a Representation of a Model. There can be several Views associated with a Model. It interacts with the model via a reference to the model object itself.
  • Controller: a link between a User and the System he manipulates by providing the means for user interaction with the data represented by the model. Controller received commands from User and sends messages to views: a view never knows about user input such as keystrokes and mouse operations.

Note that the model has no specific knowledge of either its controllers or its views -- - it contains no internal references to either.

Why MVC ?

On his site Reenskaug says that the structure is meant to be useful "if the user needs to see the same model element simultaneously in different contexts and/or from different viewpoints".

Multiple controllers manipulate the model; multiple views display the data in the model, and change as the state of the model changes.
Multiple controllers manipulate the model; multiple views display the data in the model, and change as the state of the model changes.

How to implement MVC Architecture ?

The Java programming language provides support for the MVC architecture with two classes:

  • Observer -- any object that wishes to be notified when the state of another object changes. The model will be a subtype of Observable.
  • Observable -- any object whose state may be of interest, and in whom another object may register an interest. The view will be a subtype of observer.

They provide the mechanism by which the views can be automatically notified of changes in the model. Object references to the model in both the controller and the view allow access to data in the model.

In Web Application Frameworks such as Struts, the model resides in the Business Logic Layer and is implemented with Java Beans, the Views are implemented by JSP pages and the Controllers are implemented by Java Servlets.

MVC Architecture is also the foundation of the new popular framework Ruby On Rails.

Design Patterns: Elements of Reusable Object-Oriented Software
Amazon Price: $34.95
List Price: $59.99
Head First Design Patterns
Amazon Price: $27.98
List Price: $49.99
Design Patterns Explained: A New Perspective on Object-Oriented Design (2nd Edition)
Amazon Price: $28.00
List Price: $54.99
Elemental Design Patterns
Amazon Price: $28.90
List Price: $44.99

Comments

Prof. Chandrakant 3 years ago

the article foub=nd very much intresting and it is really Excellent

hotwebideas profile image

hotwebideas Level 3 Commenter 12 months ago

I do MVC programming in PHP, but the comment is the same. I wrote a hub about using models or the lack of models which would make MVC programming easier for beginners at http://hubpages.com/hub/Zend-Framework-Do-we-reall

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    • No HTML is allowed in comments, but URLs will be hyperlinked
    • Comments are not for promoting your Hubs or other sites

    Please wait working