How to use mediators to manage dynamic number of instances driven by models

tangent's Avatar


31 Dec, 2012 12:31 PM


Let's suppose I have a WindowModel, a WindowView, and a WindowViewMediator, where the mediator would listen to the context event from the WindowModel and manipulate WindowView accordingly.

Next, the code needs to support dynamic number of windows, and each WindowView would have its own WindowModel. Given that mediator listens to context event which seems to be a global event, how can the mediator differentiate event relevant to the view it is handling? Is there a better paradigm to handle this situation?


p.s. I apologize if the similar question has been asked before, my search keywords didn't yield the answer I was looking for in this discussion board.

  1. Support Staff 1 Posted by Shaun Smith on 02 Jan, 2013 06:24 PM

    Shaun Smith's Avatar

    Hi Tangent,

    In terms of paradigms, the "Model" part of MVCS is not really a good fit for that kind of thing. When a model falls more into the view side of things, when it exists purely for the benefit of a view, then the Presentation Model pattern is often a better fit. But that might not be what you're after.

    Using MVCS you can implement "selectors" (unique identifiers) and then differentiate events in your mediators by only handling events whose identifiers match. Your model's API would be similar in that all method calls would involve the identifiers in some way.

    If you're using RL2 the easiest thing to do would be to create a child context for each Window.

  2. 2 Posted by tangent on 03 Jan, 2013 01:07 PM

    tangent's Avatar


    Thanks for the reply! I am excited to see RL2's support for child context, which sounds like a good way to go. Are there any samples on child context and best practices out there?

  3. Support Staff 3 Posted by Shaun Smith on 03 Jan, 2013 05:49 PM

    Shaun Smith's Avatar

    Nope, nothing that I know of unfortunately. The MVCSBundle includes the ModularityExtension - which automatically adds child contexts to parent contexts based on the display list hierarchy. You'll probably want to install the ScopedEventDispatcherExtension to allow communication between contexts.

  4. Support Staff 4 Posted by Ondina D.F. on 14 Jan, 2013 11:32 AM

    Ondina D.F.'s Avatar

    Hey Tangent,

    I'm assuming this is resolved, so I’m going to close this thread now.
    Feel free to re-open it, if need be.


  5. Ondina D.F. closed this discussion on 14 Jan, 2013 11:32 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