净谦

导航

适配器模式

package structual.Adapter.one;

/**
* 适配器模式,
* 把一个类的接口换成客户端期待的接口形式,使原本因为接口不匹配不能工作的两个类能够在一起工作
* @author zhangchy
*
*/


/**
* 类适配器模式
*
* 与Adeptee是继承关系
* 可以置换Adaptee的方法方便,能够重写和覆盖
*/


class Adeptee{
public void methord1(){
System.out.println("this is methord1");
}
}


interface Itarget{
public void methord1();
public void methord2();
}

class Adapter extends Adeptee implements Itarget{
public void methord1(String mett){
System.out.println("this is methord1111");
}
public void methord2(){
System.out.println("this is methord2");
}
}

public class AdapterPattern {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Itarget adapter = new Adapter();
adapter.methord1();
adapter.methord2();
}

}

posted on 2012-03-20 17:55  康安V  阅读(165)  评论(0)    收藏  举报