Subclassing Mediators

Owen's Avatar


11 Dec, 2009 08:39 PM

I have a set up where I have a mediator that subclasses another. They both control the same kind of component (a TileList in this case). The view property of the superclass is set to be injected with a TileList, which is then inherited by the subclass. What I'm trying to figure out is how to tell the context to inject the superclass in one case and the subclass in another.

Is there a method for handling this kind of scenario? I saw Joel's suggestion of using a setter injection elsewhere (here, in fact: but the topic was slightly different in that case, so I wasn't sure if it was relevant.


  1. Support Staff 1 Posted by Shaun Smith on 11 Dec, 2009 08:52 PM

    Shaun Smith's Avatar

    Hi Owen,

    I think the best solution here is to create an abstract mediator that you extend into the two subclasses. Subclassing a concrete Mediator that already has it's view component dependency defined is always going to be tricky to work around - and not a very clean approach when you think about what you're extending and what you're trying to swap out (the view dependency).

    Does that help?

  2. 2 Posted by Owen on 11 Dec, 2009 09:26 PM

    Owen's Avatar


    Thanks for the swift reply! The view used by both Mediators is the same. The problem I have is that I can't figure out how to assign different Mediators to the same view class.
    In the context I'd have (FlickrTileListMediator extends PaginatedTileListMediator):

    mediatorMap.mapView( TileList, PaginatedTileListMediator );
    mediatorMap.mapView( TileList, FlickrTileListMediator );

    But obviously, the second mapping has the same view as the first. I don't know if it's possible to use a named mapping in this case?

    I can see a solution that uses the approach you've described, which would be to extend TileList and PaginatedTileListMediator and use those to map instead.

    Something like:
    mediatorMap.mapView( TileList, StandardTileListMediator );
    mediatorMap.mapView( FlickrTileList, FlickrTileListMediator );

    Do you think that'd be the best approach?

  3. Support Staff 3 Posted by Shaun Smith on 11 Dec, 2009 09:36 PM

    Shaun Smith's Avatar

    Aha! So you'd like to map multiple Mediators to a single concrete view component inside a context? That's not possible with the way RL currently handles it's mappings - it might be possible in the future. For now, you'd have to extend one of the view components like you suggested. But I believe you'd need to use the third param to indicate the injection type for the mapping:

    Something like:
    mediatorMap.mapView( TileList, StandardTileListMediator );
    mediatorMap.mapView( FlickrTileList, FlickrTileListMediator, TileList );

    These limitations are performance related - we haven't thought of a minimal-impact solution to this kind of mapping. Yet :)

  4. 4 Posted by Owen on 11 Dec, 2009 10:25 PM

    Owen's Avatar

    That worked a treat. Thanks for your help :)

    I realised that actually I didn't need to create an abstract mediator, since what I needed to do was to provide a second view for the mapping. In fact, I couldn't anyway since most of the code in the base class relied on having the view.

    So, now I have 2 views, PaginatedTileList, which maps to PaginatedTileListMediator (the super class) and FlickrTileList, which maps to FlickrTileListMediator (the sub class). I don't think I needed to have PaginatedTileList at all, but thought it best, since I'm bound to need another kind of tile list somewhere else ;)

  5. Till Schneidereit closed this discussion on 15 Dec, 2009 06:35 PM.

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