int main() { RemoteControl *rc = new RemoteControl(); Light * light = new Light(); LightOffCommand * lightOffcmd = new LightOffCommand(light); LightOnCommand * lightOncmd = new LightOnCommand(light); rc->setCommand(lightOffcmd); rc->buttonPressed(); rc->setCommand(lightOncmd); rc->buttonPressed(); system("PAUSE"); return 0; }
// The client int main() { // Receiver Light *light = new Light; // concrete Command objects LightOnCommand *lightOn = new LightOnCommand(light); LightOffCommand *lightOff = new LightOffCommand(light); // invoker objects RemoteControl *control = new RemoteControl; // execute control->setCommand(lightOn); control->buttonPressed(); control->setCommand(lightOff); control->buttonPressed(); delete light, lightOn, lightOff, control; return 0; }