How much work should a mediator do?

rob's Avatar

rob

17 Apr, 2010 05:54 AM via web

My mediators tend to only listen for events dispatched by other mediators or models and then respond to those events by running a method on the component that they are mediating. I try to never manipulate the details of the viewComponent with the mediator and if something needs to be passed to the viewComponent I'll do it as an actual function call rather than using a setter.

ex: viewComponent.setSomeThing(someThing:MyThing) rather than viewComponent.someThing = someThing;

I realize it's basically the same thing but I prefer the former.

I do this so that the Mediator acts only as a conduit between the application and the component. It hears events from the component and notifies the app. It hears events from the app and runs some function or gives something to the component.

However I've seen mediators used to actually manipulate the inner workings of a component (setting the text of a text field member inside the component for example) but to me this seems inherently confusing because you are then manipulating the component in two places and it's not entirely clear where component logic lives.

I'd like to get the community's opinion on this.

Thank you!

  1. Support Staff 2 Posted by Joel Hooks on 17 Apr, 2010 05:58 AM

    Joel Hooks's Avatar

    I approach it much the same way you do with the mediator being a "switch board" for communication. Many people feel that the mediator should hold any logic the view component might need. I think that view components should be self-contained and not quite as stupid. They should be stupid regarding knowledge of siblings and the greater application, but I think that leveraging Flex within view components and allowing them to manage their basic state is OK.

    I don't see a problem with either approach as long as you are consistant within your application.

  2. 3 Posted by rob on 17 Apr, 2010 06:09 AM

    rob's Avatar

    Yes I think consistency is the key then. If you are going to put component logic in the mediator then the component should really only consist of event dispatches and be as simple as possible. Otherwise it can be unclear where state changes actually happen.

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