LearningTech

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:
    def __init__(self):
        pass

    def execute(self):
        print('Executing Command')