Sitemap
Design Patterns In Python

Common GoF (Gang of Four) Design Patterns Implemented in Python.

Member-only story

Command Design Pattern

4 min readApr 10, 2019

--

The Command pattern is a behavioural design pattern, in which an abstraction exists between an object that invokes a command, and the object that performs it.

E.g., a button will call the Invoker, that will call a pre-registered Command, that the Receiver will perform.

A Concrete Class will delegate a request to a command object, instead of implementing the request directly.

Using a command design pattern allows you to separate concerns and to solve problems of the concerns independently of each other.

E.g., logging the execution of a command and its outcome.

The command pattern is a good solution for implementing UNDO/REDO functionality into your application.

Uses:

  • GUI Buttons, menus
  • Macro recording
  • Multi-level undo/redo
  • Networking — send whole command objects across a network, even as a batch
  • Parallel processing or thread pools
  • Transactional behaviour
  • Wizards

Terminology

  • Receiver: The object that will receive and execute the command.
  • Invoker: The object that sends the command to the receiver. E.g., A button.
  • Command Object: Itself, an object, that implements an execute, or action method, and contains all required information to execute it.

--

--

Design Patterns In Python
Design Patterns In Python

Published in Design Patterns In Python

Common GoF (Gang of Four) Design Patterns Implemented in Python.

Sean Bradley
Sean Bradley

Written by Sean Bradley

Developer of real time, low latency, high availability, asynchronous, multi threaded, remotely managed, fully automated and monitored solutions.