装饰器模式

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");
    }
}

你可能感兴趣的:(装饰器模式)