3.2. Command
We have an Invoker and a Receiver. This pattern uses a “Command” todelegate the method call against the Receiver and presents the samemethod “execute”. Therefore, the Invoker just knows to call “execute” toprocess the Command of the client. The Receiver is decoupled from theInvoker.
The second aspect of this pattern is the undo(), which undoes the methodexecute(). Command can also be aggregated to combine more complexcommands with minimum copy-paste and relying on composition overinheritance.
- Symfony2: SF2 Commands that can be run from the CLI are built withjust the Command pattern in mind
- big CLI tools use subcommands to distribute various tasks and packthem in “modules”, each of these can be implemented with the Commandpattern (e.g. vagrant)
You can also find this code on GitHub
CommandInterface.php
Receiver.php
Invoker.php