Can you have the proxy implement an interface that can be shared between
the proxy and the real class?  AS3 doesn't really provide a mechanism
for you to simulate AOP transparently, you can of course code-gen a
subclass of your main object that would probably take care of things for
you, but it will be hard to do generically just within the language.

 

Matt

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Chen Bekor
Sent: Wednesday, December 06, 2006 11:51 PM
To: [email protected]
Subject: [flexcoders] flash.utils.Proxy questions

 

I am trying to extend flash.utils.Proxy so that I can intercept calls
made on an innerObject and provide cross cutting services/advices like
writing to a log or caching... (AOP...)

The big problem is that the user of the innerObject needs to be aware
of the ProxyClass otherwise - calls will not be intercepted.

for example:

a proxy factory class looks like this- 

public class ProxyFactory
{
private var _target:*;

public function ProxyFactory(target:*){
_target = target;
}

public function GetProxy():*{
var proxy:AOPProxy = new AOPProxy(_target);
return (proxy);
}
}

and the usage:

var person:Person = factory.GetProxy();

this will produce a runtime casting exception!!

the fix is to do something like this:

var person:AOPProxy = factory.GetProxy();

or even -

var person:* = factory.GetProxy();

BUT - this is bad because the user of the factory is aware of the
proxy AND he loose code assist... he cannot see the properties of the
Person Class.

Does any body know of a better way (maybe creating runtime code
generated proxies??- code emission...)

Thanks,

Chen Bekor
Software Architect.

 

Reply via email to