definition:The request is wrapped in the object as a command and passed to the calling object. The call object looks for the appropriate object that can process the command and pass the command to the corresponding object, and the object executes the command.
Features:
1. Reduced system coupling.
2. New commands can be easily added to the system.
Applications in enterprise-level development and common frameworks: transactions, action controllers for struts
Example:
public class Demo { public static void main(String[] args) { Reicever reicever = new Reicever(); Command command = new ActualCommand(reicever); Invoker invoker = new Invoker(); (command); (); } } /** * The real executor of the command, there may be different executors for different commands */ class Reicever{ public void action(){ ("()"); } } /** * Command interface, also to unify the subsequent commands */ interface Command{ public void excute(); } /** * In actual command objects, there may be many different command objects */ class ActualCommand implements Command{ private Reicever reicever; public ActualCommand(Reicever reicever) { = reicever; } public void excute() { (); } } /** * The command issuer */ class Invoker{ private List<Command> commands = new ArrayList<>(); public void addCommand(Command command){ (command); } public void call(){ for(Command c:commands){ (); } } }
There are very few cases when the command mode is used alone, and it is usually used in combination with the memo mode.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.