What is the Command pattern? Where do you meet it in a Java backend?
Short answer
Command turns a request into an object (execute(), sometimes undo()), separating who creates the command from who runs it. Once a command is an object, you can queue, log, retry, run it later, or undo it.
3 points to say:
- Command = a request packaged as an object: who creates it, who runs it and when are decoupled.
- In Java:
Runnable/Callablesubmitted to an executor, job queues, undo stacks, command messages via a broker/outbox. - Versus Strategy: a Command is "what to do" (one action with its data), a Strategy is "how to do it".
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.