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: Notification best practices  (Read 7534 times)
ricardokirkner
Jr. Member
**
Posts: 18


View Profile Email
« on: July 18, 2008, 10:09:29 »

When dispatching notifications for informing about data availability (on proxies), what's the best practice: to send the data as the notification body, or to save the data as a property of the proxy, and let the mediator retrieve the data by calling up the proxy?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: July 18, 2008, 10:49:53 »

If you send the data, it is a looser coupling.

While it's an accepted practice to retrieve the Proxy and get the data, if this one Notification introduces the coupling then pass the data, don't make that coupling and be better off for it.

Sometimes a Mediator and a Proxy will communicate often enough, we design the Mediator to retrieve and cache a reference to the Proxy at onRegister so that it doesn't have to retrieve many times throughout runtime. If this is the case and a collaboration has already been established between a Mediator and a Proxy, and that Mediator will be the only observer, feel free to omit sending the data so you don't need to cast the note body. Allow the Mediator to access a typed getter on the Proxy instead.

And if it will be a Command that uses the data, if that Command does nothing else with the Proxy except retrieve the data, then send the data in the note body and let the Command cast it, omitting a call to retrieve the Proxy, since the Command will go away after execution and would have to do that retrieval each time.

-=Cliff>
Logged
ricardokirkner
Jr. Member
**
Posts: 18


View Profile Email
« Reply #2 on: July 18, 2008, 11:26:47 »

great explanation. thank you.
Logged
Pages: [1]
Print