page_title: Command pattern
section_title: UML class and sequence diagram
hierarchical_section_title: Command pattern / Structure / UML class and sequence diagram
caption_attribution_description: English: A sample UML class and sequence diagram for the Command design pattern.
context_page_description: In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters.
  Four terms always associated with the command pattern are command, receiver, invoker and client. A command object knows about receiver and invokes a method of the receiver. Values for parameters of the receiver method are stored in the command. The receiver object to execute these methods is also stored in the command object by aggregation. The receiver then does the work when the execute method in command is called. An invoker object knows how to execute a command, and optionally does bookkeeping about the command execution. The invoker does not know anything about a concrete command, it knows only about the command interface. Invoker object, command objects and receiver objects are held by a client object, the client decides which receiver objects it assigns to the command objects, and which commands it assigns to the invoker.
context_section_description: In the above UML class diagram, the Invoker class doesn't implement a request directly.
  Instead, Invoker refers to the Command interface to perform a request (command.execute()), which makes the Invoker independent of how the request is performed.
  The Command1 class implements the Command interface by performing an action on a receiver (receiver1.action1()).
  The UML sequence diagram
  shows the run-time interactions: The Invoker object calls execute() on a Command1 object.
  Command1 calls action1() on a Receiver1 object,
  which performs the request.
caption: A sample UML class and sequence diagram for the Command design pattern. [3]
exif: {}