One of the more common extensions to this design pattern is to provide for composite commands. In the Combining two applications into one recipe, we showed one way to create composites. This is another way, based on defining a new command that implements a combination of existing commands:
class CommandSequence(Command): def __init__(self, *commands): self.commands = [command() for command in commands] def execute(self, options): for command in self.commands: command.execute(options)
This class will accept other Command classes via the *commands parameter. This sequence will combine all of the positional argument values. From the classes, it will build the individual class instances.
We might use this CommandSequence class ...