Command Patterns
A command pattern is a design pattern that is used to issue commands to the system. Depending on the functional and technical requirements of the application, different command patterns can be used. Each pattern is designed to solve a specific problem or to meet a specific requirement. Some patterns dictate the nature of the implementation, while others address specific concerns like atomicity or notification.
Attributes
The attributes to consider when deciding for a pattern to implement a solution to a specific problem are:
- Atomicity: How to ensure that the command is atomic? How to handle failures and rollbacks?
- Notification: How to ensure that the command progress is notified to the user or administrators?
- Orchestration: How to handle long-running commands? How to ensure that the command is executed in the correct order? How to handle errors and exceptions? How to implement continuation and approval/rejection?
- Performance: How to ensure that the command is performant?
- Evolution: How to ensure that the command can evolve? How to handle changes in the requirements?
For each attributes we need to consider the following questions:
- How complex actually is the attribute? Do not try to design a solution for a problem that does not exist.
- How much value the system will get from the attribute? Do not incur in technical debt for a feature that is not used.
- How open to evolution the attribute is? Do not design a solution that will not be able to evolve with the system.