As per the definition given by gang of four command pattern facilitates encapsulating a command request as an object – which means representing an action as an object
- This pattern helps us to persists a request/action in the form of an object
- The command pattern is a behavioral design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time
- It will allow you to have each of these actions as a separate object which you can save, retrieve and perform operations on the respective objects
- It’s basically designing our commands as objects
This pattern can be used everything from websites implementing complicated features like undo to implementing simple features like parsing command line arguments in console application.
I have used Job Life Cycle commands as an example to demonstrate command pattern. I hope that you would find it interesting and use it in your own applications.