Re: MVC - The right way

From: Tony Weston (aweston_at_connectfree.co.uk)
Date: 09/12/04


Date: 12 Sep 2004 05:53:46 -0700

The way MVC is structured on Apple macs OS X, is NOT the MVC that was
originally conceived. Mac MVC works something like this:

  View <==> Controller <==> Model(s)

The view is completely dumb..... just a screen designed list of
components, that are publicly accessible. The controller interrogates
the Model, for the data, and populates the View with the data the
view needs. By working this way, the controller must know all the
fields the View will show to the user, and therefore be strongly
coupled..... Any change to the View, must require a change to the
controller.

This is the wrong way to do things. Consider a very complicated
screen, with many tabs/combo boxes/ etc. On this screen, consider a
combo box, that allows selection of, (for example) a unit of currency.
This combo could be used in many screens, so the code to populate the
list of currency data within this combo, would have to be duplicated
in each and every controller, where a similar combo exists. This, is
considered correct (because, it is thought re-use is hard)! on a
complex screen like this, the controller will become very large with
code that is duplicated many times in different controllers,
throughout the system.....

With the traditional MVC, the Currency combobox can be considered a
view all in itself, and itself retrieve the list of currencies it
needs by a currency model, it has created an instance of. The code to
copy the different currencies, would be imbedded within the combobox
(or in real world terms, you would have a CurrencyCombo, that extended
combobox, with additional code in the constructor to retrieve and
interrogate a currency model) . A panel that needs the currency combo,
just adds a new currency combo to itself. The retrieving of the list
of currencies will be taken care of internally within the component.
The instance of this currency combobox, will be part of a larger view,
which will interrogate a different model, to 'set' the currency code
of the combo to be that required.
  This imbedding of a view within another view, is based on the
combination pattern, and is mentioned in Design Patterns (Gang of
four), to be how the View part of the MVC is put together. Supposed
MVC designs, that have a single model per screen/panel/window, where
this model contains a massive data structure containing all the data,
in all the components, are flawed.

There was a post a few weeks ago in this group titled 'Data-aware GUI'
components, in what Fredrik Bertilsson wondered why not have
components that populate themselves with data. I did agree with him,
that writing a flawed MVC application, using many components, would be
difficult, and a maintenance headache......

The original model of MVC however, as I have described, does allow
components to be data aware, and populate themselves. Rather than the
components querying a database directly, however, they instantiate,
and retrieve data from a model the component itself retrieves an
instance of, and this model is which takes care of the database query.



Relevant Pages

  • Re: MVC - The right way
    ... > The way MVC is structured on Apple macs OS X, is NOT the MVC that was ... the controller must know all the ... > combo box, that allows selection of, a unit of currency. ... populates the currency popup. ...
    (comp.object)
  • Re: GUI in C#
    ... decouple "event-driven programming" from the MVC concept. ... > the controller code sits in the U/I layer, ... even though the pattern is described that way. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A few questions regarding MVC
    ... circa 1970 version or some modern variation? ... Using the classic MVC archticture as a guide to understanding modern ... controller can take the appropriate actions. ... views are observers <- model ...
    (comp.object)
  • Re: ttk::checkbutton - I think, its a bug
    ... If your implementation of MVC is a View that directly updates the Model, ... So you don't consider the bindings, and the code behind the bindings, ... to be considered a controller? ... what happens if you have a widget for the same data on several ...
    (comp.lang.tcl)
  • Re: MVC in C++
    ... Things are now flowing more along the classic MVC lines. ... > struct Observable ... > string version; ... In that case the Controller would trigger a model update *and it* could ...
    (comp.object)