Created
April 10, 2019 20:18
-
-
Save Sean-Bradley/e8a33e0d60ad8101c4cc939e45964766 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
# The Client is the main python app | |
# The Light is the Reciever | |
LIGHT = Light() | |
# Create Commands | |
SWITCH_ON = SwitchOnCommand(LIGHT) | |
SWITCH_OFF = SwitchOffCommand(LIGHT) | |
# Register the commands with the invoker (Switch) | |
SWITCH = Switch() | |
SWITCH.register("ON", SWITCH_ON) | |
SWITCH.register("OFF", SWITCH_OFF) | |
# Execute the commands that are registered on the Invoker | |
SWITCH.execute("ON") | |
SWITCH.execute("OFF") | |
SWITCH.execute("ON") | |
SWITCH.execute("OFF") | |
# For fun, we can see the history | |
print(SWITCH.history) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment