Example #1
0
int main() {
	RemoteControl* control = new RemoteControl();
	
	Receiver* light = new Light();

	Command* lightsOn = new OnCommand( light );
	Command* lightsOff = new OffCommand( light );
	
	//switch on light
	control->setCommand( lightsOn );
	control->pressButton();

	//switch off light
	control->setCommand( lightsOff );
	control->pressButton();

	Receiver* tv = new Television();

	Command* tvOn = new OnCommand( tv );
	Command* tvOff = new OffCommand( tv );

	//switch on TV
	control->setCommand( tvOn );
	control->pressButton();

	//switch off TV
	control->setCommand( tvOff );
	control->pressButton();

	
	return 0;
}
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;
}
Example #3
0
int main() {
	auto light = std::make_shared<Light>();
	auto comLightOn = std::shared_ptr<Command>(std::make_shared<LightOnCommand>(light));
	auto comLightOff = std::shared_ptr<Command>(std::make_shared<LightOffCommand>(light));

	auto ceilingFan = std::make_shared<CeilingFan>();
	auto comCeilingOn = std::shared_ptr<Command>(std::make_shared<CeilingFanOnCommand>(ceilingFan));
	auto comCeilingOff = std::shared_ptr<Command>(std::make_shared<CeilingFanOffCommand>(ceilingFan));

	auto stereo = std::make_shared<Stereo>();
	auto comStereoOn = std::shared_ptr<Command>(std::make_shared<StereoOnCommand>(stereo));
	auto comStereoOff = std::shared_ptr<Command>(std::make_shared<StereoOffCommand>(stereo));

	MacroCommand::CommandArray vecOn = {comLightOn, comCeilingOn, comStereoOn};
	MacroCommand::CommandArray vecOff = {comLightOff, comCeilingOff, comStereoOff};

	auto comMacroOn = std::shared_ptr<Command>(std::make_shared<MacroCommand>(vecOn));
	auto comMacroOff = std::shared_ptr<Command>(std::make_shared<MacroCommand>(vecOff));


	RemoteControl r;
	r.setCommand(comMacroOn, comMacroOff, 0);
	r.setCommand(comLightOn, comLightOff, 1);
	r.onButtonWasPushed(1);
	r.undoButtonWasPushed();
	r.onButtonWasPushed(0);
}
Example #4
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;
}