Mediator responsibilities

Timur's Avatar


04 Aug, 2011 11:05 PM


I'm putting together a small project that loads an XML file, and from it loads images on the screen. Simple. If the image src is not bound to any components in the view, but rather the images are loaded through dynamically created loaders that are then added to the view, whose responsibility is it to draw them and to store the loaders' state and position? So that later, if they need to be removed, which actor would be tasked with this? Not the view, since it should be dumb to this. Would it be a concerted effort of mediator, command, and model? I'm curious the hear opinions on the recommended approach.



  1. Support Staff 1 Posted by creynders on 05 Aug, 2011 09:11 AM

    creynders's Avatar

    IMO it certainly is the views responsibility. That's what views are for: displaying data.
    In general however I pass the loader's content to the view not the loader itself and clean up all loader instances since they are no longer needed.
    In short: a service controls the loaders, when they (or one of them, depends on the use case) finish loading, their content is sent as a payload with an event, picked up by the interested mediator and passed to its corresponding view. The view is responsible for displaying the image and removing it when necessary.

  2. 2 Posted by Timur on 05 Aug, 2011 04:08 PM

    Timur's Avatar

    Hi creynders,

    In general however I pass the loader's content to the view not the loader itself and clean up all loader instances since they are no longer needed.

    Do you mean that you pass the loader.content to the view as the event payload? I'm unclear on that. If your service clears up the unneeded loaders, since, in your example, they are a by-product and need to be discarded, like a rocket booster, then how and who controls the removal of the content itself on the view.

    Thanks for you reply,


  3. Support Staff 3 Posted by creynders on 06 Aug, 2011 02:45 PM

    creynders's Avatar

    Yes, I pass loader.content as the event payload.

    The removal of content in the view is controlled by the view itself since that's exactly what views are for.

  4. 4 Posted by Timur on 07 Aug, 2011 02:08 AM

    Timur's Avatar

    Thanks creynders.

    So, you're passing the images in the event, and storing them in your view, or do you have reference to them in your model somewhere as well? What if you'd need to reposition them later, who keeps state (my original question)?


  5. Support Staff 5 Posted by creynders on 07 Aug, 2011 07:03 AM

    creynders's Avatar

    Short answer: the view keeps state, since (in this case) it concerns only view state.

    Longer answer:
    In most cases the view manages and stores position, alpha, etc, since this is explicit presentation data. There's no need to create separate models and make your application unnecessarily complex. However there are a few situations in which I would store view state in models:

    • if the view state is shared among several views or needs to be persistent between view display cycles.

    • if the view state needs to be accessed by other framework actors.

    • if view state is configurable

    An example would be an image editing application, since the view state is actually application state. But even then I wouldn't store ALL view state in models, just the data that falls under above 3 situations.

  6. 6 Posted by Timur on 09 Aug, 2011 03:36 AM

    Timur's Avatar

    Thanks for your insight, creynders.


  7. Timur closed this discussion on 09 Aug, 2011 03:36 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