A few questions regarding MVC



I have a few questions regarding the MVC pattern.

The View
========
The view provides the user
1. A way in which to interact with the model by generating events
2. A way in which to view the model
However, it does not directly manipulate the model. Any interractions
with the model are passed onto the respective controller so that the
controller can take the appropriate actions. So for example, where the
view displays some text in a text box:

1. User hits keyboard - generates event
2. Controller handles event by updating text in model
3. Model informs view that state has changed. View updates text
- Would the view update the entire state, or can it know somehow
exactly what has changed?
- Java Swing is not MVC, as the text box stores it's own state

Is this correct?

The controller
==============
Controller
- Handles all events from the view
- Each view has one controller (a single controller may be composed
of 'sub-controllers', eg: a sub-controller per event) (like at
http://www.theserverside.com/tt/articles/article.tss?l=JavaGUIDev
which shows there are models for each subcomponent, which are all part
of a larger domain model).

Is this correct?

The View/Controller relationship
================================
http://java.sun.com/blueprints/patterns/MVC-detailed.html shows that
the controller communicates with the view, and is labelled in the
diagram as 'view selection'.

If I understand the pattern correctly the controller should never be
asking the view for anything to do with the state. For example, if a
key was pressed in a text field, the controller won't query the text
field to see what is currently entered (this is done in Swing), as the
label shouldn't be updating it's own state (instead this information
would be passed to the controller in the generated event, eg:
keyPressedEvent.GetKeyPressed() would return 'a'). So does this
interraction represent those events that require the view to change,
but not the state (eg: resizing the window, scrollbars, etc.)? I
suppose then the view would store it's own state, which is not part of
the model.

'Design Patterns' (gamma et al) states: "The View-Controller
relationship is an example of the Strategy (315) design pattern. A
Strategy is an object that represents an algorithm. It's useful when
you want to replace the algorithm either statically or dynamically,
when you have a lot of variants of the algorithm, or when the
algorithm has complex data structures that you want to encapsulate."
So in MVC is the AlgorithmInterface() of the Strategy Interface (as on
page 315 of design patterns, gamma et al) the interface which contains
the event handlers, ie: Button1Pressed(), Button2Pressed(), etc..
methods?

The Model/Controller
====================
http://www.javadude.com/articles/vaddmvc1/mvc1.htm shows that the
model communicating with the controller ('I have changed'). AFAIK,
this is not MVC - the model never communicates with the controller
(only the other way around).

Thanks

Taras
.


Quantcast