definition: The request is wrapped in an object in the form of a command and passed to the calling object. The calling object looks for the appropriate object that can handle the command, and passes the command to the appropriate object, which executes the command.
Characteristics:
1, reduce the system coupling degree.
2. New commands can be easily added to the system.
Enterprise-class development and applications in common frameworks: Transaction, Struts action controller
Instance:
public class Demo {public
static void Main (string[] args) {
reicever reicever = new Reicever ();
Command command = new Actualcommand (reicever);
Invoker invoker = new Invoker ();
Invoker.addcommand (command);
Invoker.call ();
}
/**
* Command true performer, for different commands may have different command performer
/class reicever{public
Void action () {
System.out.println ("Reicever.action ()");
}
/**
* Command interface, also for the back of the following unified command *
*
interface command{public
void Excute ();
}
/**
* Actual Command object, there may be many different command objects
/class Actualcommand implements command{
private reicever reicever;
Public Actualcommand (Reicever reicever) {
this.reicever = reicever;
}
public void Excute () {
reicever.action ();
}
}
/**
* Command issued by * *
class invoker{
private list<command> commands = new arraylist<> ();
public void AddCommand (Command command) {
commands.add (command);
}
public void Call () {for
(Command c:commands) {
c.excute ()}
}}
The command mode is used alone in very few situations, and is generally used in combination with Memo mode.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.