Mediator optimization

ps's Avatar

ps

17 Nov, 2011 10:27 AM

Hey,

I have a situation when: I create many (several hundreds) objects which update their properties with model. But also, when model changes, they update themselves if changes related to them. My questions is: what is faster, create mediator for every object and make them dispatch/listen to events from model by themselves, or create a manager class which is listening to this event and sorts it to those objects which are related to model update?

ps

  1. 1 Posted by Vlado on 17 Nov, 2011 10:52 AM

    Vlado's Avatar

    If there aren't several hundred sorts of changes that the objects(views?) are interested in, I'd create a single mediator and mediate a parent object, that forwards the changes to the many objects. So the answer is to create both (a manager object) and a single mediator, that mediates it.
    Of course the above makes less sense if those objects aren't related to each other in some way.
    Hope this helps.

  2. 2 Posted by Stray on 17 Nov, 2011 10:59 AM

    Stray's Avatar

    Another option is to use a single mediator and then use this to dispatch signals which are injected (manually, doesn't have to be using auto DI) into the views.

    If you're familiar with signals and want more info on this approach, shout.

    Stray

  3. 3 Posted by ps on 17 Nov, 2011 11:12 AM

    ps's Avatar

    @Vlado objects(views) are not related to each other so your solution should be OK. One thing which worries me is that I have to store them in an array (so they are not independent), and then clear them manually. The thing is not easy cause those objects are different classes in different containers etc. I would have to manually administer GC.

    @Stray, yes, I'm using signals in my project. (Signals, SignalCommand, SignalMediator). I would like to hear more on this approach please.

  4. Ondina D.F. closed this discussion on 31 Dec, 2011 09:45 AM.

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