Facade pattern and Adapter paattern summary
-
Upload
vincent-chu -
Category
Software
-
view
202 -
download
1
description
Transcript of Facade pattern and Adapter paattern summary
READING GROUP - FACADE, ADAPTER
Presenter: Vincent Chu 2014/04/21
Agenda
• Facade
• What is Facade?
• Example
• Conclusion
!
!
• Adapter
• What is Adapter
• Example
• Conclusion
!
WHAT IS FACADE?Provide a unified interface to a set of interfaces in a
subsystem. Facade define s a higher-level interface that
makes the subsystem easier to use.
About Facade Pattern
目的 簡化原有系統的使用方式定義自己的介面
問題 只需使用一個複雜系統中的一小部份子系統用特別的方式與系統互動
解決方案 為client建立一個新的介面來使用子系統
參與者及協作者 Facade為client提供了一個特別介面來簡化系統的使用(完全沒有說到重點)
結果 Facade簡化了對子系統的操作方式Facade並不完整,因此某些功能會無法使用
實作方式 建立新介面所需的classes讓這些class可以使用原有的系統(廢話)
Example of Facade
• The “Football” is the best example I can find!
Example of Facade
• The Amazon 1-Click order may be as dangerous as nuclear weapon to my wife.
Conclusion
• Dictionary said…
• façade or facade (fəˈsɑːd, fæ-, fəˈsɑːd, fæ-)
• the face of a building, esp the main front.
用行話來說,facade就叫『包一下』
• CRM web service API
WHAT IS ADAPTER?Convert the interface of a class into another interface
that the clients expect. Adapter lets classes work together that could not otherwise because of incompatible interfaces.
About Adapter Pattern
目的 讓非你控制的物件可以跟某個目標介面匹配
問題系統的資料和行為都正確,但介面不相容通常在需要使用一個洐生自既有抽象類別的東西時
解決方案 Adapter為目的interface提供一個wrapper
參與者及協作者Adapter將adaptee的介面做了轉換,讓client在使用target時,不知道其實target是透過adapter在使用adaptee的功能
結果Adapter pattern讓新的class可以使用既存的object,而不需因為既存object的interface而受限
實作方式用新的class把既存的object包起來透過新class操作既存object的介面client使用新的class
About Adapter Pattern
An Adapter for client to use legacy object with an
interface which we already have.
An Wrapper for client to use legacy object with no
interface restricted. Wrapper are also kind of
Adapter.
Example of Adapter
• International Plug Adapter is the best sample of Adapter Pattern!!
Ref: http://www.amazon.com/Kensington-33117-International-Travel-Adapter/dp/B0002H4YUI/
Example of Adapter
• ADO.NET
• Provides adapter for client to access various kind of database without(?) problem.
• Once you have new kind of vintage database need to access with, just implement your own ADO.NET interfaces. How simple(?) it is!!
Ref: http://msdn.microsoft.com/en-us/library/vstudio/27y4ybxw(v=vs.100).aspx
Conclusion
• Like Facade, Adapter also ‘wrapping’ object but they still have miner difference.
!Facade Adapter
是否存在既有類別? Yes Yes
是否須使用某個特定介面? No Yes
物件需要多型嗎? No Maybe
需要更簡單的介面嗎? Yes No
Conclusion
Facade pattern的目的是簡化介面,而Adapter pattern的目的則是必須適應一個現有的介面。
簡言之,Facade pattern簡化了介面,Adapter pattern則將一個介面轉化為另一個。
Thanks for your time.