星期一, 十二月 19, 2005
BusinessDelegate、Proxy及其它的区别
Delegate and Proxy, though similar, serve different purposes.
IMHO, Proxy provides some 'transparency' in that client may(or should) not be aware
of the existence of Proxy. So, Proxy's interface should be very simliar to or even
exactly the same as the Service. In general, proxy and service implement the same
interface.
For the case of BusinessDelegate, IMHO, it is NOT a proxy becuase it does not share
the same interface with BusinessService. However, the 'BusinessService' instance,
BusinessDelegate gets from ServiceLocator, could be a Proxy of the real Service.
这三段的意思就是Proxy是纯代理角色,不做任何关乎其所在层面的处理,它继承它所代理的interface。个人认为:这个只是对business端的代理,如果是client端的呢?而businessdelegate不继承businessService的interface,它可去处理它所在层面的问题,如此所讨论,在业务层,它处理底层异常(RemoteException, ServiceLoactorException....转化为BusinessException)。如此,它即可代表本层面(业务层)与表现层交互。
Proxy的主要目的应该是减少产生代价(这个观点好象在GoF的Design Pattern里看到过),而且也可以顺便把cache机制由此引入。
还有个Adapter,个人观点来看,主要目的是对异构环境的集成,比如在J2EE环境下有一部分是webServices服务,这里就需要xmlAdapter来保证服务可获取
自己也说不太清楚,可能还是没弄明白吧,把
别人的观点贴出来吧,方便以后参考:
/**********************/
BusinessDelegate 如果著重在 Delegate 上面
那就比較好了
至於是 Proxy or Adapter
那就得觀看實際上面的應用
比如說
當在製作上面有效能上面的考量
那可能就會採用 Delegate Proxy 的實作方式
因為會考慮到採取 Cache 的機制
如果考慮到的是為了整體架構上面的完整性 (這樣講對嗎?)
那或許 BusinessDelegate 就會比較像是 Adapter
但這在 Delegate 上面也就是多加上一點小動作而已
因為 BD 主要的功能就是提供一個管理的層級
並且讓 Business Tier & Presentation Tier 之間的耦合性降低 (這我想我是老調重彈了, 應該大家都懂了)
所以這其實是實作上面的不同點
稍稍變換一下 在套用 GoF 的 Design Patterns
或許就會有比較不同的風貌出來
/**********************/
Proxy以Distribution System的應用是希望能夠達到Local/Remote transparent,
負責底層的通訊機制,當然也將Cache實作於Proxy中,而Cache與DNS的概念,似
乎是一樣的.
至於Business Delegate,要負責的是降低關聯性,通常我在實做上都是用來提供
簡單的Business Method(通常與Facade中的Method相同),相信大家都看過
Core Design Patterns那本書,知道Business Delegate我們付與他的任務就是
希望能夠處理 NonApplicationException 的部分(RemoteException or CreateException..etc)將這些Exception throw為Presentation Tier Developer能夠明
白的Exception.其二,我還會在Business Delegate中做一些Verify的動作,以避免
與端呼叫但資料錯誤所造成的浪費.
至於ServiceLocator,也是放置Cache的好地方(For HomeOject Stub),但是
通常我在Presentation Tier 所建立的Service Locator都只對應Middle Tier
的ServerFacade,如此Presentation Tier 的關聯性又更為降低.
/*******************/
Application Service 對應到 use case, 屬於較高層次的 business logic.
一個 Application Service 可以使用到多個 Business Objects 或其他的 Services
多個 Application Services / use cases 也可能分享某些 Business Objects
所以 Business Objects 之間, 如果是一些 use case specific 的合作行為
不適合寫到 Business Objects 裡面.
我想可以將 Application Service 及 Business Object
看成是兩個不同層次(或granularity)的 business logic
SessionFacade(不含或很少邏輯)及Application Service(use-case specific logic)
應該都是成為 Web Service Endpoint Interface 的選擇
但書上是建議可以再加一層 Web Service Broker 來加強 coarse-graned.
ps. 雖然 Web Service Broker 也可用來作為處理
xml2java/deserialization 及 java2xml/serialization 的地方,
但這些其實底層的 AppServer 應該多半可以幫你作到
--Unknown @ 21:07
0回复: