Pattern · Core

Command

Turn a request into a standalone object — so you can parameterize, queue, log, and UNDO actions, and decouple the thing that triggers an action from the thing that performs it.

Asked atAmazonMicrosoftFigma
step 1 / 7
1/2Invoker hard-wired to the receiver
calls light.on()
Remote
+ press()
Light
+ on()
+ off()
Invoker hard-wired to the receiver
1class Remote {
2 Light light;
3 void press(){ light.on(); } // wired straight to the Light
4}

The Remote calls light.on() directly. It is hard-wired to one receiver and one action.