Theoretical: I have application with many buttons, can I use one mediator between all of them?

giza3three's Avatar


01 May, 2011 07:56 AM

Hi, I am planning a very simple xml reader / editor app.

1) If I have 10+ buttons, can they use one mediator, with the mediator / context going to a different command depending on buttons' name?

2) Or do I have to create a new mediator for each one? I was hoping to 'many same objects to one mediator', then I can have a single UIMediator or such to manage the UI.

3)The same for a game, if the gameObj is clickable, can I have one mediator which manages all clickable gameObj's ?

From what I can see so far, it seems RL can become bloated very quickly... please help !! :)

  1. 1 Posted by krasimir on 01 May, 2011 08:53 AM

    krasimir's Avatar


    I really like to work with RL, but personally I'm using it to build the main structure of the application. I.e. if I have 10+ buttons I prefer to put them in a view which has a mediator and actually the view manages the events coming from the buttons. Then when some of the buttons is clicked the view dispatches an event which in most of the cases is redispatched by the mediator.

  2. 2 Posted by giza3three on 01 May, 2011 09:09 AM

    giza3three's Avatar

    ok cool, so I dont have to use RL rigidly? I think Ill explore your method, just using the bits I need :) thanks.

  3. 3 Posted by krasimir on 01 May, 2011 09:14 AM

    krasimir's Avatar

    RL is a great tool when you have modular application and various parts which have to communicate between each other, but I guess using it for every little piece of functionality will make the application too complex.

  4. 4 Posted by Stray on 01 May, 2011 09:40 AM

    Stray's Avatar

    Mediator granularity is very flexible!

    There are 3 approaches to 'lots of buttons on one component' other than mediating them individually (and we'd usually recommend a composite mediator approach like you want to use here).

    They are:

    1) You can send customised events from the view to the mediator, to be redispatched.

    2) You can use getters on the view to expose the buttons and listen to these directly for their click events, via the eventMap in your mediator (addViewListener is just a helper method for this):

    override public function onRegister():void
    eventMap.mapListener(view.someButton, MouseEvent.CLICK, someClickHandler, MouseEvent);
    eventMap.mapListener(view.someOtherButton, MouseEvent.CLICK, someClickHandler, MouseEvent);


    3) You can use Signals between your view and your mediator to indicate which button was clicked, and the SignalMediator / SignalMap to handle these.

    Personally my favourite is number 3, but if you're not familiar with Signals then go for 1 or 2. The 'right' selection probably depends on how reusable your view is.

    However, if the 'many buttons' don't naturally belong in the same view, I don't consider a one line unique-mediator for each button to be making your app 'bloated'. Lots of small, focussed, well named, classes is a good way to work in my experience.

    I hope that helps,


  5. Stray closed this discussion on 25 May, 2011 08:31 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