How aredthsanchez/command_design_pattern works
This is a small Java example of the Command pattern. Main creates a light receiver and on/off commands, assigns each command to a remote control, and presses its button. The remote control dispatches execution through the Command interface; each concrete command calls the corresponding LightSwitch operation. The excerpts show this runtime flow, but no broader product capabilities or persistent state.
Main entry points: Main.java Main · RemoteControl.java RemoteControl · TurnOn.java TurnOn · TurnOff.java TurnOff
Components 6
Control
- Main
Main.java - RemoteControl
RemoteControl.java
Light receiver
- LightSwitch
LightSwitch.java
Connections 6
- Main → RemoteControl: configures and presses
Main.java - Main → TurnOn: creates
Main.java - Main → TurnOff: creates
Main.java - RemoteControl → Command: dispatches execute
RemoteControl.java - TurnOn → LightSwitch: calls on
TurnOn.java - TurnOff → LightSwitch: calls off
TurnOff.java