设计模式

设计模式--适配器模式

2019-03-21  本文已影响0人  二妹是只猫

模式介绍

定义与类型

使用场景

优点

缺点

扩展

类适配器
Class-Adapter
定义

简单示例

public class Adaptee {
    public void Operation3(){
        System.out.println("被适配者的方法");
    }

}
public interface Target {
    void opration1();
    void opration2();
}
public class Adapter extends Adaptee implements Target{
    @Override
    public void opration2() {
        super. opration3();
    }
    //...
}

对象适配器
Object-Adapter
定义

简单示例

public class Adapter implements Target{
  private  Adaptee adaptee = new Adaptee()
    @Override
    public void opration2() {
        adaptee. opration3();
    }
    //...
}
上一篇 下一篇

猜你喜欢

热点阅读