O'Reilly logo

Learning Python Design Patterns by Gennadiy Zlobin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Use cases of the Command design pattern

It is better to apply the command in the following cases:

  • When you need to keep a history of requests. An invoker can save command instances after calling its execute method to implement history functionality somewhere.
  • When you need to implement callback functionality. If you pass to the invoker two objects one after another, the second object will be a callback for the first.
  • When you need requests to be handled at variant times or in variant orders. To achieve this, you can pass the command objects to different invokers, which are invoked by different conditions.
  • When the invoker should be decoupled from the object handling the invocation.
  • When you need to implement the undo functionality. To achieve this, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required