Re: MVC - The right way
From: Tony Weston (aweston_at_connectfree.co.uk)
Date: 09/12/04
- Next message: Robert C. Martin: "Re: Model View Controller basics."
- Previous message: Mark Nicholls: "Re: Is this the DIP confusion?"
- In reply to: Tony Weston: "MVC - The right way"
- Next in thread: Fredrik Bertilsson: "Re: MVC - The right way"
- Reply: Fredrik Bertilsson: "Re: MVC - The right way"
- Reply: Jonathan Hendry: "Re: MVC - The right way"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Robert C. Martin: "Re: Model View Controller basics."
- Previous message: Mark Nicholls: "Re: Is this the DIP confusion?"
- In reply to: Tony Weston: "MVC - The right way"
- Next in thread: Fredrik Bertilsson: "Re: MVC - The right way"
- Reply: Fredrik Bertilsson: "Re: MVC - The right way"
- Reply: Jonathan Hendry: "Re: MVC - The right way"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|