package cn.bunny.pattern5.demo1;

import cn.bunny.pattern5.demo1.command.*;

public class Main {
    public static void main(String[] args) {
        // 创建接收者对象
        TV tv = new TV();
        AirConditioner airConditioner = new AirConditioner();

        // 创建命令对象并绑定接收者
        Command tvOn = new TVOnCommand(tv);
        Command tvOff = new TVOffCommand(tv);
        Command airConditionerOn = new AirConditionerOnCommand(airConditioner);
        Command airConditionerOff = new AirConditionerOffCommand(airConditioner);

        // 创建遥控器（调用者）
        RemoteControl remoteControl = new RemoteControl();

        // 按钮1：打开电视
        remoteControl.setCommand(tvOn);
        remoteControl.pressButton();  // 输出：电视机打开了

        // 按钮2：关闭电视
        remoteControl.setCommand(tvOff);
        remoteControl.pressButton();  // 输出：电视机关闭了

        // 按钮3：打开空调
        remoteControl.setCommand(airConditionerOn);
        remoteControl.pressButton();  // 输出：空调打开了

        // 按钮4：关闭空调
        remoteControl.setCommand(airConditionerOff);
        remoteControl.pressButton();  // 输出：空调关闭了
    }
}
