PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: skasssam on October 24, 2011, 09:22:13



Title: Share Values in all Models?
Post by: skasssam on October 24, 2011, 09:22:13
I want to share a value (global) between all my Models. What is the most sound way to do this?

I can set these values when the application loads but where would the best place to put these values so that the Models would have access to them?

TIA,
Shinan


Title: Re: Share Values in all Models?
Post by: puremvc on October 24, 2011, 10:25:35
I assume you mean your Proxies.

If these are fixed values you could put them in a constants file, of course.

If not, then you should make a Proxy for holding those values, and pass a reference to that Proxy into the constructors of the other Proxies when they are created. Have those Proxies keep the reference, and they'll all be able to collaborate with the common Proxy. And Commands and Mediators will also be able retrieve that Proxy if they need access to it.


:
/**
* Constructor.
*
* The SandwichProxy collaborates with the
* JamProxy and the BreadProxy to ensure
* consistency of the domain data. Requiring
* them on the constructor ensures they
* will be present.
*/
public function SandwichProxy( jamProxy:JamProxy, breadProxy:BreadProxy )
{
super( NAME );
this.jamProxy   = jamProxy;
this.breadProxy = breadProxy;
}

-=Cliff>