PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: ricardokirkner on July 18, 2008, 10:09:29



Title: Notification best practices
Post by: ricardokirkner 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?


Title: Re: Notification best practices
Post by: puremvc 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>


Title: Re: Notification best practices
Post by: ricardokirkner on July 18, 2008, 11:26:47
great explanation. thank you.