Commands can be found every where once one knows what to look for. Often commands are hidden from sight and we can produce better designs if we simply take a step back to formally define the commands in our system.
The original "command pattern" is from GoF design patterns and unfortunately is a very specific object-orientated pattern.
Now a days when people say "command", they tend to mean the C in CQRS.
We shall define a command as an immutable object with a name and arguments. Commands are sent over a command bus. Commands are routed to command handlers.
A concrete example is JSON object (command) sent over the network (command bus) and routed to express middleware (command handler).
An user performs a series of commands to achieve their objective.
login (credentials)
register (event)
create team (name)
Product management define epics and stories which can be broken down into commands user perform.
An user interface implemented by a framework such as React, performs a series of commands to update component state and DOM.
render react component to dom (component, domElement)
update team name in react component (name)
create team (name)
JavaScript application that are cleanly defined by a set of commands can easily be tested with Cypress.
State management libraries might have a different name for commands. For example, Redux calls them Action.
Browser automation tools such as Puppeteer is a series of commands to control a Chrome instance.
Modern graphics APIs such as WebGPU allow developers to directly create a batch of commands and send them to the graphics hardware.
On the other hand, commands are annoying implicit in some event driven frameworks such as Cycle.
A database such as MongoDB offers an API which is a series of commands to insert, find, update, and delete documents.
insert (collection, document)
find (collection, query)
update(collection, updateOperations)
delete(collection, deleteFilter)
The database itself is backed by a series of commands to the filesystem. The filesystem is persisted to disk which a series of NVMe commands to the physical drive. The solid state drive controller implements a series of flash chip commands.
Testing patterns such as Arrange, Act and Assert are a series of commands.
Ditto for Cucumber Given, When, Then. By formalizing a production/service into a series of commands, one can easily do Behaviour-driven development.
Commands are every where, but what can we say about commands generally? Commands have many interesting properties.
Do you see everything in terms of commands? We like to hear from you! Battlefy is hiring.