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: Mediate a Mediator  (Read 10097 times)
Posts: 1

View Profile Email
« on: October 10, 2007, 12:01:28 »


First time caller, long time listener.

Seriously though, I'm confused about something I hope that someone could help me out with. I've read the documentation and I've created 3 applications with pureMVC, (Calculator, CD-Rom Media Presentation, 3/4ths the way done with a stupid little poker game), it's really great! Thank you for building it! My confusion comes in when I start thinking about a mediator mediating other mediators. Specifically in the HelloFlash. By the way, my usage doesn't go beyond Flash (I haven't played with Flex yet). Is it safe to say pureMVC requires/recommends a core Mediator?

Second question, if I subclass View, would it be considered bad practice to intercept notifyObservers() to search for my startup event and use that to seed my mediators in the view with the stage?

Forgive me if this is common knowledge, I'm not very versed in MVC and have just picked up as3 a bit over a week ago.

Thank you for any response (except the mean ones  ;D)
Global Moderator
Hero Member
Posts: 2871

View Profile WWW Email
« Reply #1 on: October 10, 2007, 09:27:56 »

Hi Ryan,

Generally speaking, Mediators are meant only to manage their View Components, so there usually isn't an Uber-Mediator.

In HelloFlash, we have a StageMediator which mediates the Stage object. Primarily to listen for ScrollWheel and MouseUp events when the user scrolls the mouse wheel or drops a dragged Sprite. It also listens for Notifications to create new Sprites.

And we have the HelloSpriteMediator which listens for events from a HelloSprite instance, handling drop (yes, you have to listen here, as well, because the drop could happen inside the dragged Sprite or outside it on the Stage). It handles Notifications to scale (sent by the StageMediator on ScrollWheel events). It also listens for divide events sent from the sprite when dragged. It packages the information about the current Sprite's location, color and vector and sends a Notification to create the new Sprite, which is handled by the StageMediator.

So there's no real hierarchy of Mediators happening in HelloFlash. We simply have a collaboration pattern between 2 Mediator classes.

The thing with Flex is that we let the MXML Application instantiate itself and its children as it will PRIOR to attaching the PureMVC system to it.

So, when you begin looking at the Flex examples, you'll see that sometimes there is an ApplicationMediator, which manages the top level Flex Application instance. It may in turn be responsible for creating the other Mediators, by instantiating them and attaching them to the already created children of the Application. This creation of Mediators by other Mediators is generally a convenience, since the Application can expose properties that are the functional View Components that need Mediators attached. However the relationship generally stops there. In order to isolate all the black boxes that make up the view, and make them reusable, we don't tie them to each other, we communicate with them via Notification.

Hope this helps.
Pages: [1]