Assembling data from several models

x's Avatar


14 Dec, 2011 04:46 PM

In my Application there are models which hold different kinds of data. When an event, e.g. "country selected", occurs, some models are modified and View A should update with data that comes from several of those models. I could think of different approaches:
a) The view's mediator holds references to the models, retrieves the data and updates the view
b) I create a command that reacts upon the event, retrieves the data from the models, assembles it into a new, view-specific event that the view's mediator listens to
c) I create a "meta-model" which acts as some kind of proxy to the other models. Upon changes to the "sub-models", it assembles the data into an event the view's mediator listens to

I think a) is not really good, since it bypasses the given channels of the framework. c) is also not really optimal, because the more sub-models are involved, the bigger the meta-model gets. But I'm also not quite sure if b) is the way to go, but I can't really put my finger on it.

Apart from everything, I really don't like the idea of creating a huge data package with several kinds of data in the form of an event class.

Are there any best practices on how to structure the data flow in those cases? Is my feeling about coupling view(-mediator) classes to model classes instead of events is smelly reasonable?


  1. Support Staff 1 Posted by creynders on 14 Dec, 2011 05:44 PM

    creynders's Avatar

    Al 3 options are viable, although personally I tend to skip a) since it's not really "clean". But it all depends on the application and what it's for.
    c) is actually sort of an expansion of b) since you'll still need (a) command(s) which assemble(s) all the data and put it in the model. I tend to go for b) unless if I know that the same query will be reused in which case it makes sense to store the results in a separate model or even model of models.
    I can't really think of any real issues with b) it's definitely a lot cleaner than a)

  2. Ondina D.F. closed this discussion on 17 Jan, 2012 10:53 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac