I want to give my two cents ...
The original command template separates Command objects from Receiver objects, because the responsibilities of the two sets are different.
Receiver belongs to the business logic of the application. These types must exist outside the template. In a practical case, Receiver was probably already present in the code base, before the commands.
For example, inventing a banking application, the receiver can be represented by the following type:
public class Account { private final double balance;
One of the goals of the command design pattern is to provide a single, uniform, and standard way to perform operations on a set of objects (i.e., receivers). They donโt care how to implement real business logic. This will limit the reuse of code that implements business logic.
For this reason, the Command implementation should redirect information to the Receiver . This follows an example.
public class DepositCommand implements Command { private final Account account;
In conclusion, imho, the statement contained in the accepted answer is incorrect.
A receiver is a relic of C / C ++ in which the method that is being called is separated from the object to be called.
source share