I find your response curious, Larry. You speak as though there is only one
interpretation of MVC.
For example, in this article
http://ootips.org/mvc-pattern.html
The controller accepts the input, routes it through the model and brings it
back to the view. In rich client event driven programming, that means that
the controller code sits in the U/I layer, as does the view code... leaving
only the model code to exist anywhere else. No need for a data layer in
this model. This article, which is a summation of a chapter in a book on OO
programming, directly implies this.
On the other hand, this book, from Sun
http://java.sun.com/blueprints/guid...prise_applications_2e/web-tier/web-tier5.html
Describes the View as containing all logic for both user input and output,
while the Model maintains data and the Controller dispatches commands
between the two. (This is a better explaination, IMHO).
In the purist MVC structure, everything refers to everything. Problem is:
this doesn't compile very well. What really happens is that you factor up
to interfaces, and everyone is supposed to use interfaces to do the work.
This imposes a firm structure on the application that can really help
seperate the concerns, and make the application more adaptable to change.
The strength of MVC lies in the use of these interfaces.
The reason that I state that event driven programming is somewhat at odds
with MVC is that in event-driven development, events do not come FIRST to
the controller, even though the pattern is described that way. (For
example, here's a description of how the controller works: "Events typically
cause a controller to change a model, or view, or both. Whenever a
controller changes a model's data or properties, all dependent views are
automatically updated." from
http://www.enode.com/x/markup/tutorial/mvc.html )
There is an underlying naïveté in this description. There is an attempt to
ignore the fact that there is code that is modifying the view BEFORE the
controller is informed of the event. In modern GUI systems, this is nearly
always true. From the standpoint of the business, all images and characters
on the screen are part of the view. They care about where the characters
show up, what order tabs occur in, when validations occur, how many windows
appear... In the MVC pattern, this logic is part of the controller, yet in
modern GUI systems, 10-15% of this logic sits directly in the View classes
themselves, often configured directly into generic controls.
In practice, we end up passing commands and data modifications, often on a
field-by-field basis (rather than character-by-character, which is left to
the text control or drop-list control, etc). I've occasionally seen it done
on a screen-by-screen basis. We pass commands to the controller, which
interprets behavior, and, occasionally, calls the view back to get the data
that it will pass to the model to manage data manipulation and persistence.
One other thing that occurs in practice, but is often glossed over, is that
the controller owns and creates the view objects. So, the controller has to
be created first, and has to track and manage a set of these objects (tied
to the portion of the view that is displayed at the moment). It is the
complexity of these objects themselves that I am concerned about.
The traditional description of the view being automatically updated requires
that the controller pass a View object to the model to render itself with.
However, the view objects, if they are designed to be invoked by the model
objects directly, become very "command driven" because the model doesn't
know what portion of the view is actually visible (nor should it). This
ability to "automatically" update the view can, and often does, lead to
inordinately complicated logic in the view classes. This is where I think
the OP was heading. (I may have been mistaken... won't be the first time

.
That is why I use MVC for partitioning, but not for the dynamic structure
that I want my application to follow. I do not pass view objects to the
model to self-render. I tend to rely much more frequently on the layers
pattern. In this context, the model DOESN"T have any binding to the Views.
It isn't aware that the data is being viewed so it does not inform the view
that a data element has changed. In a sense, it is much more passive. The
Controller (now in the UI layer) will be informed of events, will interpret
them by using the contents of the controls themselves, will pass data into
the model, and will then call Render objects that know about the model.
These Render objects can extract the data that they need to copy information
back into the controls.
In other words, instead of having a single event start in the U/I, loop
through the controller, into the model, and directly back to the U/I, I'm
suggesting that your code is much simpler, and easier to maintain, if the
model doesn't know about its own display. Rather, the U/I knows what is
displayed in it, and can redraw itself by knowing about the model. This
means that an event begins in the U/I, is passed to the controller. The
controller gathers data from the controls, and either calls the view objects
themselves to effect structural changes (opening and closing windows,
manipulating the display), or calls the model to handle the data. The model
returns to the controller. The controller then calls the Render objects to
render the model data. The Model doesn't call either the controller or the
view in this layout and is effectively not bound to either.
Your coupling is reduced, since the model doesn't need to know about the
view. This isn't the MVC pattern at all... it is the Layers pattern. If
you reread my text above and read the term "Business Objects" every time I
said "Model", you will see how I got here.
What leads me to this spot is pragmatism. In a programming model where
events originate from U/I objects, and the U/I can enforce rules through
configuration, the notion of a view DRIVEN BY a model is out of touch with
current practice. It is expensive and unnecessary, IMHO. That is a
personal opinion, of course, but one that I am sure I share with others.
I hope that this clarifies my statements.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--