刷题刷出新高度,偷偷领先!偷偷领先!偷偷领先! 关注我们,悄悄成为最优秀的自己!
(1)Command是一个接口,定义了一个execute方法,用于执行命令。
(2)在LightOnCommand类的execute方法中,应调用Light对象的on方法,以执行开灯命令。
(3)在LightOffCommand类的execute方法中,应调用Light对象的off方法,以执行关灯命令。
(4)在RemoteControl类的setCommand方法中,将传入的onCommand对象赋值给onCommands数组的指定位置,即onCommands[slot] = onCommand。
(5)同样,在RemoteControl类的setCommand方法中,将传入的offCommand对象赋值给offCommands数组的指定位置,即offCommands[slot] = offCommand。
(6)在RemoteControl类的onButtonWasPushed方法中,调用onCommands数组中对应位置的execute方法,即onCommands[slot].execute()。
(7)在RemoteControl类的offButtonWasPushed方法中,调用offCommands数组中对应位置的execute方法,即offCommands[slot].execute()。
让学习像火箭一样快速,微信扫码,获取考试解析、体验刷题服务,开启你的学习加速器!
