> For the complete documentation index, see [llms.txt](https://amartyushov.gitbook.io/tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://amartyushov.gitbook.io/tech/programming-languages/java/patterns/command.md).

# Command

\#behavioral&#x20;

:link:[LINK](https://refactoring.guru/design-patterns/command)

{% hint style="info" %}
Example:

You are in the restaurant, a waiter approaches you and quickly takes your order, writing it down on a piece of paper. The waiter goes to the kitchen and sticks the order on the wall. After a while, the order gets to the chef, who reads it and cooks the meal accordingly. The cook places the meal on a tray along with the order. The waiter discovers the tray, checks the order to make sure everything is as you wanted it, and brings everything to your table.

The **paper order** serves **as a command**. It remains in a queue until the chef is ready to serve it (**chef is a receiver**). The order contains all the relevant information required to cook the meal. It allows the chef to start cooking right away instead of running around clarifying the order details from you directly.&#x20;
{% endhint %}

## Structure

<figure><img src="https://415484505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LxtoAXZwwOc4XGto8vb%2Fuploads%2Fx1NL9BpFNVuYXHGF93fK%2FScreenshot%202023-03-14%20at%2021.29.54.png?alt=media&amp;token=2fb91e9b-01c5-4464-96ae-21b6ecc94a41" alt=""><figcaption></figcaption></figure>
