When we have to implement a scenario where a list of commands needs to get executed, or actions needs to be performed based on the input given by the client, we can implement a command pattern.
It acts like a macro, a command that is translated to a set of actions to be performed by a particular device/service. It makes our code extensible and we can add new commands without changing the existing code. It also reduces the coupling of code.
For example, if there are two buttons of a remote ( On and Off ), we want to use the same two buttons on more than one items selected in the menu. Like fan, Television, Tubelight. By selecting one of the items if we press On, it should send a command.
Posted Date:- 2021-09-06 20:52:03