Real-world examples
When we go to a restaurant for dinner, we give the order to the waiter. The check (usually paper) that they use to write the order on is an example of a command. After writing the order, the waiter places it in the check queue that is executed by the cook. Each check is independent and can be used to execute many different commands, for example, one command for each item that will be cooked.
As you would expect, we also have several examples in software. Here are two I can think of:
- PyQt is the Python binding of the QT toolkit. PyQt contains a
QAction
class that models an action as a command. Extra optional information is supported for every action, such as description, tooltip, shortcut, and more (j.mp/qaction). - Git Cola (j.mp/git-cola), a Git GUI written in Python, uses the Command pattern to modify the model, amend a commit, apply a different election, check out, and so forth (j.mp/git-cola-code).