Design Patterns in ActionScript-Proxy

aim-128x128Have you ever use HTTP-proxy or some other proxy? When you’re in a relatively isolated environment, such as the LAN in your company, maybe you’ll need it. Actually, when I was an intern in an IT company, I always used the HTTP-proxy to login the MSN and surf on the internet. When I used MSN or surf on the net, I can’t feel the existence of the proxy. And this is the role of a proxy. And this can be express as follows.

clip_image001

Actually, the client proxy is just like a middle layer between the client and the real server. And in this layer, the network administrator can do many things, such as, he can group people by using authorization mechanism that different group will get different service, or he can allow or forbid you to surf some sites. All those can be done in the proxy layer.

Further more, layer is an important concept in computer science; you can see it everywhere, such as the HAL (Hardware Abstraction Layer) in the OS, or the N-tier architecture website and so on. With layer, we can do many things, for example, we move all the platform-dependent properties in to the HAL, and then when we want to move the OS from one platform to the other, we just need to rewrite the HAL.

And here we use the proxy layer to solve some problems which happen during we access the subject directly, such as the security, the spending or something else.

The intent of the corresponding pattern in the GoF is as follows.

Provide a surrogate or placeholder for another object to control access to it.

– By THE GoF BOOK

Now, the example time :)

We put the RealServer and the ClientProxy into a package named outer and put the Client into the default package. And then, change the modifier of the RealServer to default, and the ClientProxy to public, so that, the Client can’t access the RealServer Directly.

If you try to do this, server = new RealServer(“server”) in the Client, then you’ll get a complier error, it means the Client can’t access the RealServer as you want.

Now, we can use the proxy to bridge the Client and the RealServer.

private var server:Server;

server = new ClientProxy(serverName);
server.getRequest();
server.sendResponse();

If the Client wants to visit the server, it can only through the proxy. So you can do what you want to control the visit :) Download Download Full Project

Enjoy!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

3 Responses to “Design Patterns in ActionScript-Proxy”

  1. Unblock Me says:

    Just wanted to thank you for a really good post. I found it quite useful and will check your site often.

  2. I found your blog on google and read a few of your other posts. Look forward to reading more from you in the future.

  3. Anyone using a HTTP-Destination in SM59 with Proxy? I’m using user/password, but fail with “ProxyAuthenticationRequired”-Error. Strange…

Leave a Reply