View Single Post
  #1 (permalink)  
Old 04-01-2008, 05:13 AM
jegan jegan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 161
jegan is on a distinguished road
Default Model View Controller

The Model View Controller pattern was invented in a Smalltalk context for decoupling the graphical interface of an application from the code that actually does the work. It turned out to be an very important idea that affected how much Smalltalk code was built and is applicable to other object-oriented languages as well.
The Model

In MVC the model is the code that carries out some task. It is built with no necessary concern for how it will "look and feel" when presented to the user. It has a purely functional interface, meaning that it has a set of public functions that can be used to achieve all of its functionality. Some of the functions are query methods that permit a "user" to get information about the current state of the model. Others are mutator methods that permit the state to be modified.

However, a model must be able to "register" views and it must be able to "notify" all of its registered views when any of its functions cause its state to be changed.

In Java a Model consists of one or more classes that extend the class java.util.Observable. This superclass will provide the register/notify infrastructure needed to support a set of views.
Many Views

A model in MVC can have several views. Two examples are the rows and columns view of a spreadsheet and the pie chart view of some column in the same spreadsheet. A view provides graphical user interface (GUI) components for a model. It gets the values that it displays by querying the model of which it is a view.

When a user manipulates a view of a model, the view informs a controller of the desired change.

In Java the views are built of AWT or SWING components. However, views must implement the java.util.Observer interface.
Many Controllers

Views in MVC are associated with controllers that update the model as necessary when a user interacts with an associated view. The controller can call mutator methods of the model to get it to update its state. Of course, then the model will notify ALL registered views that a change has been made and so they will update what they display to the user as appropriate.

In Java the controllers are the listeners in the Java event structure.
__________________
Thanks & Regards,
Jegan CBK
"We will either find a way, or make one!”
Reply With Quote
Sponsored Links