美文网首页
装饰器模式

装饰器模式

作者: laosijikaichele | 来源:发表于2018-06-05 17:00 被阅读8次
public interface Car {

    void move();

}
public class DecoratorCar implements Car {

    private Car c;

    public void move(){
        c.move();
    }

    DecoratorCar(Car c) {
        this.c = c;
    }
}

public class FlyCar extends DecoratorCar {

    FlyCar(Car c) {
        super(c);
    }

    public void move() {
        super.move();
        System.out.println("fly");
    }
}

public class RealCar implements Car  {

    public void move(){
        System.out.println("real");
    }
}

相关文章

网友评论

      本文标题:装饰器模式

      本文链接:https://www.haomeiwen.com/subject/bnkmsftx.html