Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought

Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Author Topic: hierarchy of mediators  (Read 9406 times)
Posts: 1

View Profile Email
« on: April 01, 2008, 02:08:15 »

I was prompted to post this question after reading the answer in "mediate a mediator"
But since that was such an old post, am starting a new thread.

I am very excited about the PureMVC framework, but I believe I am not thinking correctly about mediators, so I'm hoping for some correction here.

I am porting a project to AS3 PureMVC, which was AS2 MVC, but kind of a home grown MVC.

The structure of the project is a collection of modules which are managed by a layout manager, and each module can have many view elements within it, some of which are themselves containers of view elements. The structure is defined in an external data file which is read in at startup, and the layout, modules, and sub-view elements are created based on that data.

I started with a layoutMediator, which has a sprite ui element, this adds in modules which are also mediators and also have sprite ui elements, down to buttons which I have also separated into mediators and sprite ui elements. I like the platform independence this gives even to buttons (can reuse the mediator) but maybe I'm going too far. For example, something like a combo-box is composed of several UI elements, and it would have a mediator, but itself could be a part of the UI of a module, implying a mediator hierarchy.

So my question is, it seems that I should make a hierarchy of mediators since the module mediators belong to the layout mediator, and the mediators for the UI within the module clearly belong to their respective modules, but, the answer I sighted above indicates that mediators should not be hierarchical, so how should I be thinking of the PureMVC structure of such an application?

Global Moderator
Hero Member
Posts: 2871

View Profile WWW Email
« Reply #1 on: April 02, 2008, 08:00:33 »

Mediators are not hierarchical. If they communicate with each other, they do so by Notification to reduce coupling between them.

A Mediator might create another Mediator, for instance if a Mediator's child is a ViewStack, which defers the creation of its children until you navigate to them. In that case the ViewStack's Mediator would hear an event bubbled from the child on creationComplete, and respond by creating the new Mediator and passing it the reference to the newly created child. Or you might choose to pass the reference in a Notification to a Command, which creates the new Mediator, if you'd like.

And yes, you're probably going a bit deep with the Mediators. As a rule start out with fewer mediators and more complex viewComponents, then as a Mediator becomes more monolithic, split it into more fine grained ones. This will lead to better maintainability as it contains the explosion of classes. And better performance, since every object creation operation takes time.

Pages: [1]