Design patterns are used to solve software problems.
You need to understand the problem before trying to understand the solution (in this case, the command template)
The problems with which the command template is applied relate to object A (client) calling the method in object B (receiver), so the receiver is part of the problem, not part of the solution.
The solution or idea proposed by the command template is to encapsulate a method call from A to B into an object (Command), in fact this is close to the formal definition of the template. When you manage the request as an object, you can solve some problems or implement some functions. (you will also need other parts such as Invoker)
This list can give you some good examples of what problems o functions are suitable for the command template.
Note: the Comamnd template is not required for decoupling, in fact the most common example of template implementation, the client needs to create a new recipient instance, so we can not talk about decoupling here.
source share