Skip to content

Instantly share code, notes, and snippets.

@Sean-Bradley
Created April 10, 2019 20:18
Show Gist options
  • Save Sean-Bradley/e8a33e0d60ad8101c4cc939e45964766 to your computer and use it in GitHub Desktop.
Save Sean-Bradley/e8a33e0d60ad8101c4cc939e45964766 to your computer and use it in GitHub Desktop.
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