Behavioral

Command

Description

Turns a request into a stand-alone object that contains all information about the request.

Where to use

  • Undo/Redo mechanisms.
  • \n
  • Job Queues.

Real World Example

A text editor. 'Copy', 'Paste', 'Type' are all Command objects. You can put them in a stack to Undo them.

Code Example

class Command:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Command')