This repository has been archived on 2022-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
patterns/command/remote/app.d

58 lines
2.2 KiB
D

module command.remote.app;
import command.remote.remotecontrol;
import command.remote.lightoncommand;
import command.remote.lightoffcommand;
import command.remote.light;
import command.remote.ceilingfan;
import command.remote.ceilingfanoffcommand;
import command.remote.ceilingfanoncommand;
import command.remote.garagedoorupcommand;
import command.remote.garagedoordowncommand;
import command.remote.garagedoor;
import command.remote.stereoonwithcdcommand;
import command.remote.stereo;
import command.remote.stereooffcommand;
import std.stdio : writeln;
void main()
{
auto remoteControl = new RemoteControl();
auto livingRoomLight = new Light("Living Room");
auto kitchenLight = new Light("Kitchen");
auto ceilingFan = new CeilingFan("Living Room");
auto garageDoor = new GarageDoor("Garage");
auto stereo = new Stereo("Living Room");
auto livingRoomLightOn = new LightOnCommand(livingRoomLight);
auto livingRoomLightOff = new LightOffCommand(livingRoomLight);
auto kitchenLightOn = new LightOnCommand(kitchenLight);
auto kitchenLightOff = new LightOffCommand(kitchenLight);
auto ceilingFanOn = new CeilingFanOnCommand(ceilingFan);
auto ceilingFanOff = new CeilingFanOffCommand(ceilingFan);
auto garageDoorUp = new GarageDoorUpCommand(garageDoor);
auto garageDoorDown = new GarageDoorDownCommand(garageDoor);
auto stereoOnWithCD = new StereoOnWithCDCommand(stereo);
auto stereoOff = new StereoOffCommand(stereo);
remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
remoteControl.setCommand(2, ceilingFanOn, ceilingFanOff);
remoteControl.setCommand(2, stereoOnWithCD, stereoOff);
remoteControl.setCommand(4, garageDoorUp, garageDoorDown);
writeln(remoteControl);
remoteControl.onButtonWasPressed(0);
remoteControl.offButtonWasPressed(0);
remoteControl.onButtonWasPressed(1);
remoteControl.offButtonWasPressed(1);
remoteControl.onButtonWasPressed(2);
remoteControl.offButtonWasPressed(2);
remoteControl.onButtonWasPressed(3);
remoteControl.offButtonWasPressed(3);
remoteControl.onButtonWasPressed(4);
remoteControl.offButtonWasPressed(4);
}