2011年4月18日 星期一

Gof Creational - Proxy Pattern


  • Intent


To provide a surrogate or placeholder for another object to control access to it. The most common impl are remote and virtual proxy.

在這個模式底下,其實主要的做法就是 代理者與被代理者實做同樣的介面,而代理者保有被代理者的實體,每當client端送給代理物件需求時,代理物件就以自身保有的被代理者的實體提供服務。


  • Benefits


1. 遠端proxy可以屏蔽實際提供服務的business object 的內容(將實作放在另一個物件裏頭)


2. The virtual proxy can perform optimizations- for example, by creating objects on demand. (?? 跨謀)




  • 適用情境 - when a more versatile or sophisticated reference to an object, rather than a simple pointer, is needed.

  • 常見的API - javax.ejb.EJBObject (採用proxy pattern),stub物件在client端提供了proxy物件。

  • Class Diagram


[caption id="attachment_209" align="alignnone" width="365" caption="ProxyPattern"]ProxyPattern[/caption]

沒有留言: