javase 装饰模式 (设计模式)

public interface IHouse {
    public void openTheDoor();
}

public class Myhouse implements IHouse {
    @Override
    public void openTheDoor() {
        System.out.println("门被打开了");
    }
}
public class AmericanHouse implements IHouse {
    private IHouse hosue;

    public AmericanHouse(IHouse hosue) {
        this.hosue = hosue;
    }

    @Override
    public void openTheDoor() {
        System.out.println("按美式大铁门前的开门按键");
        this.hosue.openTheDoor();
    }
}
public class Test01 {
    public static void main(String[] args) {
        Myhouse myhouse = new Myhouse();
        myhouse.openTheDoor();


        IHouse meiShihouse = new AmericanHouse(myhouse);
        meiShihouse.openTheDoor();
       
    }
}

你可能感兴趣的:(设计模式,java)