Advantages and disadvantages of Command patterns

The Command pattern has the following advantages:

  • It decouples the classes that invoke the operation from the object that knows how to execute the operation
  • It allows you to create a sequence of commands by providing a queue system
  • Extensions to add a new command is easy and can be done without changing the existing code
  • You can also define a rollback system with the Command pattern, for example, in the Wizard example, we could write a rollback method

The following are the disadvantages of the Command pattern:

  • There are a high number of classes and objects working together to achieve a goal. Application developers need to be careful developing these classes correctly.
  • Every individual command is a ConcreteCommand ...

Get Learning Python Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.