Mediators binded to menu items - is that anti-pattern already?

misiuoperator's Avatar

misiuoperator

07 Sep, 2012 01:51 PM

I got complex, multi level menu, and some of the items in that menu need to be update when application models are changing.

I.e.: i got undo/redo commands stack and menu button [undo] which needs to be notified when the stack is empty or becomes filled.

Previously i did all the job at MainMenuMediator which was observing models and reaching deep into the menu structure to find suitable buttons; though i started doubt this aproach since MainMenuMediator gets bigger and bigger.

I thought about separate mediators for every need-to-be-up-to-date menu button (they're different classes already) but i'm not sure if i'm not going into some further troubles going this way?

Sorry, for my english, all my language skill comes from reading manuals :P

  1. Support Staff 1 Posted by Ondina D.F. on 07 Sep, 2012 02:19 PM

    Ondina D.F.'s Avatar

    Hi!

    Personally, I wouldn’t mediate each menu item. MainMenuView should expose an API – public methods that MainMenuMediator would access. When Model’s data arrives, MainMenuMediator passes it to MainMenuView, which will take care of populating the components with that data, or do whatever else is needed. The logic (“reaching deep into the menu structure to find suitable buttons“) that you had in your Mediator should be in the View. When something happens in the View, it should dispatch custom events that the mediator would re-dispatch on the shared event dispatcher (to trigger commands, for example).

    When you say:
    „ MainMenuMediator which was observing Models „, do you mean you had the Models injected into your mediator?
    Perhaps you should let Commands access your Models instead. Usually, I'm not completely against injecting Models into Mediators, but in your case it might be a good idea to avoid this approach, since the Mediator is getting bigger and bigger and the logic becomes too convoluted.

    Just my opinion :)

    Ondina

  2. 2 Posted by neil on 07 Sep, 2012 02:25 PM

    neil's Avatar

    @Ondina +1

  3. 3 Posted by misiuoperator on 07 Sep, 2012 02:39 PM

    misiuoperator's Avatar

    when i was saying 'observing' i meant they're listening to models events, i hope that's ok with robotlegs practices becasue i did a lot of stuff in that way yet :P

    thanks a lot for that advice, ill try to figure it out

  4. Support Staff 4 Posted by Ondina D.F. on 07 Sep, 2012 02:48 PM

    Ondina D.F.'s Avatar

    when i was saying 'observing' i meant they're listening to models events, i hope that's ok with robotlegs practices becasue i did a lot of stuff in that way yet :P

    haha, of course it’s ok. „MainMenuMediator which was observing models“ triggered an alarm by BPP (best practices police) :P

    thanks a lot for that advice, ill try to figure it out

    No problem. Just ask, we answer. (You can re-open this discussion or start a new one)

    Ondina

  5. Ondina D.F. closed this discussion on 07 Sep, 2012 02:48 PM.

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

Keyboard shortcuts

Generic

? 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