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]
Print
Author Topic: Communication between a particular Proxy and a particular Mediator  (Read 8912 times)
Thomas B.
Jr. Member
**
Posts: 10


View Profile Email
« 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...
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 13, 2008, 07:26:03 »

The answer is C. Type is a discriminator field for just this sort of thing.

-=Cliff>
Logged
Thomas B.
Jr. Member
**
Posts: 10


View Profile Email
« Reply #2 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, 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' ?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 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>
Logged
Thomas B.
Jr. Member
**
Posts: 10


View Profile Email
« Reply #4 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...
Logged
Pages: [1]
Print