1. Concept: 將一個類的接口轉換成客戶希望的另外一個接口。Adapter模式使得原本由於接口不兼容而不能一起工作的那些類可以一起工作。(GoF)
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
2.
http://blog.csdn.net/surprisesdu/article/details/606148
一、 類的適配器模式
/**
* 客戶端類
* @author suki
*/
public class Client {
public static void main(String[] args) {
Adaptee adaptee = new Adaptee();
Target target = new Adapter();
target.sampleOperation1();
}
}
二、 對象的適配器模式
/**
* 客戶端類
* @author suki
*/
public class Client {
public static void main(String[] args) {
Adaptee adaptee = new Adaptee();
Target target = new Adapter(adaptee);
target.sampleOperation1();
}
}
3. 優先使用組合 而不是繼承 ,所以object adapter要優於class adapter