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: A question about Proxy Classes  (Read 5532 times)
carl
Newbie
*
Posts: 5


View Profile Email
« on: June 30, 2007, 01:47:24 »

Hi All,

It appears that the way Proxy classes are set up they pretty much behave like Singletons. Due to the idiom where you define a NAME constant inside of the Proxy class and retrieve the instance of the Proxy via that NAME constant:
public static const NAME:String = 'CodePeekDataProxy';

I was just curious about the intent of this design. I have tried to see if there were cases were I would use multiple instances of a single Proxy class in my own applications and I can't think of any. So this idiom makes total sense to me, but I just wanted some clarification or insight into this to make sure I was using it properly.

What would happen if you instantiate 2 Proxies of the same class? Would you only be able to retrieve the first instance using facade.retrieveProxy()? Is it a rare case that you actually need multiple instances of the same Proxy class?

Thanks,
Carl
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: June 30, 2007, 07:00:29 »

Good point, Carl.

Most times, your Proxies will only have one instance created, though we won't go to the trouble to make them Singletons. So having a NAME constant to register and retrieve the Proxy with makes sense most of the time.

But lets imagine you have a particle system, where a Proxy is responsible for holding a single particle and you have thousands of particles. The ParticleProxy holds the physics implementation; the math for affecting the particle state. Its Data Object is a ParticleVO that holds the properties for a single particle.

You probably have a ParticleFactoryProxy that dynamically creates and registers these ParticleProxies, giving them unique names and properties at creation time.

The only thing that changes since we have multiple instances registered is the fact that we can't predetermine the name assign it to a constant and refer to with a singular idiom.

The ParticleFactoryProxy will only have a single instance created, so to retrieve it:

var facade:ApplicationFacade = ApplicationFacade.getInstance();
var pfProxy:ParticleFactoryProxy = facade.retrieveProxy(ParticleFactoryProxy.NAME) as ParticleFactoryProxy;

However since we have more than one instance of ParticleProxy, we'll have to have a different way of getting the name of the one we want. We'll probably have the ParticleFactoryProxy keep a list of all the names of the particles it has generated. Then to access them, perhaps from a command, we might do something like this:

var particleNames:Array = pfProxy.getParticleNames();
for (var k:int = 0; k<particleNames.length; k++) {
    var particleProxy:ParticleProxy = facade.retrieveProxy(particleNames[k]) as ParticleProxy;
    particleProxy.updateVector();
}

Logged
Pages: [1]
Print