圖片來源:網路
一休和尚的名言:"考考你,盡管考",但是我是一考我就倒....Orz...Facade和 Front Controller 一時間也講不出個差異,於是上週老闆出的作業,就是搞清楚Facade和 Front Controller的差別和定義。話說我剛進公司時,好像也跟一堆人討論過,但是沒個結論...XD
上網Google 一下wiki其實很容易就可以知道,Facade 就是透過開放一個介面,可以把很多邏輯,和行為都封裝在裡面,用戶只要Call 這個function,就可以完成動作,並不需要知道裡面到底Call了哪些東西做了哪些行為。
圖片來源:wiki
圖片來源:wiki
而 Front Controller pattern 是使用單一物件,來處理接收其他系統所傳來的Request,通常Front Controller 會是瓶頸所在。[2] 另外Wiki上的定義:
This object can carry out common behavior, which can be modified at runtime with decorators. The handler then dispatches to command objects for behavior particular to a request.
所以Facade 和Front Controller到底有什麼不一樣?
A facade is on the other hand rather used to wrap other methods/services to provide a unified interface, hide complexity or reduce dependency on external systems. A facade is a thin wrapper that shouldn't contains any logic except the logic used to translate between the two systems. Front Controller has no such requirements.嗯...所以感覺之前好像都用錯?....囧rz...
Reference:
[1] Wiki - Facade Pattern
[2] Front Controller
沒有留言 :
張貼留言