PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: Thomas B. on February 13, 2008, 07:03:44



Title: Communication between a particular Proxy and a particular Mediator
Post by: Thomas B. on February 13, 2008, 07:03:44
Hi,

I have the following case :

[ Please have a look on MP.jpg ]

2 instances of the BlipProxy class, and 4 instances of the BlipMediator class.
An arrow from Mx to Px means that Mx retrieves Px to work with.

My question :

When BlipProxy2 is updated, a notification is sent. The four mediators will receive it, but only BlipMediator4 will have to update its view component. bM1, bM2 and bM3 mustn't react.
What is the best way to do this :

A. Every mediator keeps a reference to his frequently used Proxy (private var _blipProxy). When a BlipProxy sends a notification, he puts a reference to its instance in the body. Then, when the notification is handled by the BlipMediator, the body has to be equal to this._blipProxy.

or :

B. Give the same name to blipProxy2 and blipMediator4. The BlipMediator notification handler will check their identity to know if something must be done.

or :

C. Maybe use the "type" parameters in Notifications... but is it really a "type" ?

I can't see which is better ...

Any idea ? Thank you very much...


Title: Re: Communication between a particular Proxy and a particular Mediator
Post by: puremvc on February 13, 2008, 07:26:03
The answer is C. Type is a discriminator field for just this sort of thing.

-=Cliff>


Title: Re: Communication between a particular Proxy and a particular Mediator
Post by: Thomas B. on February 13, 2008, 11:45:20
Thanks Cliff.

Oups... I omitted to read this thread before posting : http://forums.puremvc.org/index.php?topic=231.0 (http://forums.puremvc.org/index.php?topic=231.0), sorry.

But since we're going into this topic again, can you explain why C is it the best answer ? As 'type' must be a String, we'll probably pass something like a name, so is it very different from B ? We have to give a very strong importance to our objects naming policy... An equality test between two Proxies references couldn't be more 'robust' ?


Title: Re: Communication between a particular Proxy and a particular Mediator
Post by: puremvc on February 13, 2008, 07:43:14
Unfortunately I'm on a wap browser and can't view your attachment. And I don't know what blips are.

But I'm assuming since a particular BlipProxy has a particular BlipMediator associated with it that some command creates them both at the same time.

What you need is a way for the Proxy and Mediator pair to share a unique string so that the proxy is told what to send and the mediator is told what to look for.

So on both classes, expose a sharedKey property. In the Command that creates the proxy and mediator set the sharedKey property on both to a unique string.

Thne when the proxy sends an update notification, have it send the sharedKey in the type param.

In the mediator's handleNotification switch case for the notification, make sure the notifications type is equal to the mediator's sharedKey property.

-=Cliff>


Title: Re: Communication between a particular Proxy and a particular Mediator
Post by: Thomas B. on February 14, 2008, 03:12:57
OK, if it's the good practice, I'll do it in this way.

Thanks again.

PS : my attachment is just a picture with arrows connecting M and P. And "Blip" is just my favorite french placeholder...