Design Patterns in ActionScript-Proxy

Have 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.

  1. private var server : Server ;
  2.  
  3. server = new   ClientProxy ( serverName ) ;
  4. server . getRequest () ;
  5. 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 :)DownloadDownload Full Project

Enjoy!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值