阅读下列说明和C++代码,回答问题,将解答填入答题纸的对应栏内。 【说明】 某灯具厂商欲生产一个灯具遥控器,该遥控器具有7个可编程的插槽,每个插槽都有开关按钮,对应着一个不同的灯。利用该遥控器能够统一控制房间中该厂商所有品牌灯具的开关,现采用Command(命令)模式实现该遥控器的软件部分。Command模式的类图如下图所示。 【C++代码】 classLight{public:Light(stringname){/*代码省略*/}voidon(){/*代码省略*/}//开灯voidoff(){/*代码省略*/}//关灯};classCommand{public:(1);};classLightOnCommand:publicCommand{//开灯命令private:Light*light;public:LightOnCommand(Light*light){this->light=light;}voidexecute(){(2);}};classLightOffCommand:publicCommand{//关灯命令private:Light*light;public:LightOffCommand(Light*light){this->light=light;}voidexecute(){(3);}};classRemoteControl{//遥控器private:Command*onCommands[7];Command*offCommands[7];public:RemoteControl(){/*代码省略*/}voidsetCommand(intslot,Command*onCommand,Command*offCommand){(4)=onCommand;(5)=offCommand;}voidonButtonWasPushed(intslot){(6);}voidoffButtonWasPushed(intslot){(7);}};intmain(){RemoteControl*remoteControl=newRemoteControl();Light*livingRoomLight=newLight("LivingRoom");Light*kitchenLight=newLight("kitchen");LightOnCommand*livingRoomLightOn=newLightOnCommand(livingRoomLight);LightOffCommand*livingRoomLightOff=newLightOffCommand(livingRoomLight);LightOnCommand*kitchenLightOn=newLightOnCommand(kitchenLight);LightOffCommand*kitchenLightOff=newLightOffCommand(kitchenLight);remoteControl->setCommand(0,livingRoomLightOn,livingRoomLightOff);remoteControl->setCommand(1,kitchenLightOn,kitchenLightOff);remoteControl->onButtonWasPushed(0);remoteControl->offButtonWasPushed(0);remoteControl->onButtonWasPushed(1);remoteControl->offButtonWasPushed(1);/*其余代码省略*/return0;}
(1)virtual void execute()=0 (2)light->on() (3)light->off() (4)onCommands[slot] (5)offCommands[slot] (6)onCommands[slot]->execute() (7)offCommands[slot]->execute()