From 3c374df63d42e86a12c1eede3c49ced5831447a2 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 14 Nov 2022 22:45:04 +0300 Subject: [PATCH] simple remote command --- command/simpleremotecontrol/app.d | 25 +++++++++++++++ command/simpleremotecontrol/command.d | 6 ++++ command/simpleremotecontrol/garagedoor.d | 31 +++++++++++++++++++ .../garagedooropencommand.d | 19 ++++++++++++ command/simpleremotecontrol/light.d | 16 ++++++++++ command/simpleremotecontrol/lightoffcommand.d | 19 ++++++++++++ command/simpleremotecontrol/lightoncommand.d | 19 ++++++++++++ .../simpleremotecontrol/simpleremotecontrol.d | 18 +++++++++++ 8 files changed, 153 insertions(+) create mode 100644 command/simpleremotecontrol/app.d create mode 100644 command/simpleremotecontrol/command.d create mode 100644 command/simpleremotecontrol/garagedoor.d create mode 100644 command/simpleremotecontrol/garagedooropencommand.d create mode 100644 command/simpleremotecontrol/light.d create mode 100644 command/simpleremotecontrol/lightoffcommand.d create mode 100644 command/simpleremotecontrol/lightoncommand.d create mode 100644 command/simpleremotecontrol/simpleremotecontrol.d diff --git a/command/simpleremotecontrol/app.d b/command/simpleremotecontrol/app.d new file mode 100644 index 0000000..d149b18 --- /dev/null +++ b/command/simpleremotecontrol/app.d @@ -0,0 +1,25 @@ +module command.simpleremotecontrol.app; + +import command.simpleremotecontrol.simpleremotecontrol; +import command.simpleremotecontrol.lightoncommand; +import command.simpleremotecontrol.lightoffcommand; +import command.simpleremotecontrol.light; +import command.simpleremotecontrol.garagedooropencommand; +import command.simpleremotecontrol.garagedoor; + +void main() +{ + auto remote = new SimpleRemoteControl(); + auto light = new Light(); + auto lightOn = new LightOnCommand(light); + auto lightOff = new LightOffCommand(light); + auto garageDoor = new GarageDoor(); + auto garageDoorOpen = new GarageDoorOpenCommand(garageDoor); + + remote.setCommand(lightOn); + remote.buttonWasPressed(); + remote.setCommand(lightOff); + remote.buttonWasPressed(); + remote.setCommand(garageDoorOpen); + remote.buttonWasPressed(); +} diff --git a/command/simpleremotecontrol/command.d b/command/simpleremotecontrol/command.d new file mode 100644 index 0000000..07102fd --- /dev/null +++ b/command/simpleremotecontrol/command.d @@ -0,0 +1,6 @@ +module command.simpleremotecontrol.command; + +interface Command +{ + void execute(); +} diff --git a/command/simpleremotecontrol/garagedoor.d b/command/simpleremotecontrol/garagedoor.d new file mode 100644 index 0000000..54732e5 --- /dev/null +++ b/command/simpleremotecontrol/garagedoor.d @@ -0,0 +1,31 @@ +module command.simpleremotecontrol.garagedoor; + +import std.stdio : writeln; + +class GarageDoor +{ + void up() + { + writeln("Garage Door is Open"); + } + + void down() + { + writeln("Garage Door is Closed"); + } + + void stop() + { + writeln("Garage Door is Stopped"); + } + + void lightOn() + { + writeln("Garage light is on"); + } + + void lightOff() + { + writeln("Garage light is off"); + } +} diff --git a/command/simpleremotecontrol/garagedooropencommand.d b/command/simpleremotecontrol/garagedooropencommand.d new file mode 100644 index 0000000..a3e00df --- /dev/null +++ b/command/simpleremotecontrol/garagedooropencommand.d @@ -0,0 +1,19 @@ +module command.simpleremotecontrol.garagedooropencommand; + +import command.simpleremotecontrol.command; +import command.simpleremotecontrol.garagedoor; + +class GarageDoorOpenCommand : Command +{ + GarageDoor garageDoor; + + this(GarageDoor garageDoor) + { + this.garageDoor = garageDoor; + } + + override void execute() + { + garageDoor.up(); + } +} diff --git a/command/simpleremotecontrol/light.d b/command/simpleremotecontrol/light.d new file mode 100644 index 0000000..b363b50 --- /dev/null +++ b/command/simpleremotecontrol/light.d @@ -0,0 +1,16 @@ +module command.simpleremotecontrol.light; + +import std.stdio : writeln; + +class Light +{ + void on() + { + writeln("Light is On"); + } + + void off() + { + writeln("Light is Off"); + } +} diff --git a/command/simpleremotecontrol/lightoffcommand.d b/command/simpleremotecontrol/lightoffcommand.d new file mode 100644 index 0000000..b12d1ea --- /dev/null +++ b/command/simpleremotecontrol/lightoffcommand.d @@ -0,0 +1,19 @@ +module command.simpleremotecontrol.lightoffcommand; + +import command.simpleremotecontrol.command; +import command.simpleremotecontrol.light; + +class LightOffCommand : Command +{ + Light light; + + this(Light light) + { + this.light = light; + } + + override void execute() + { + light.off(); + } +} diff --git a/command/simpleremotecontrol/lightoncommand.d b/command/simpleremotecontrol/lightoncommand.d new file mode 100644 index 0000000..0224a51 --- /dev/null +++ b/command/simpleremotecontrol/lightoncommand.d @@ -0,0 +1,19 @@ +module command.simpleremotecontrol.lightoncommand; + +import command.simpleremotecontrol.command; +import command.simpleremotecontrol.light; + +class LightOnCommand : Command +{ + Light light; + + this(Light light) + { + this.light = light; + } + + override void execute() + { + light.on(); + } +} diff --git a/command/simpleremotecontrol/simpleremotecontrol.d b/command/simpleremotecontrol/simpleremotecontrol.d new file mode 100644 index 0000000..2678b7a --- /dev/null +++ b/command/simpleremotecontrol/simpleremotecontrol.d @@ -0,0 +1,18 @@ +module command.simpleremotecontrol.simpleremotecontrol; + +import command.simpleremotecontrol.command; + +class SimpleRemoteControl +{ + Command slot; + + void setCommand(Command command) + { + slot = command; + } + + void buttonWasPressed() + { + slot.execute(); + } +}