Executive program (Command)

zhaozj2021-02-16  52

This mode. It may be a mode of change. It is also a model that is the most fixed. Because

It is relatively flexible. Common is the command package of the GUI graphics interface so even if the interface element is changed

To function constant, then it does not affect the execution effect. Just as the programming environment of the procedure.

Function package to multiple processes. Call. But Command mode. It is another advantage that you can restore

Before you have done your previous work until you don't work. This is a transactionality. This must be one

The transaction list will be maintained. The transaction rolls back. Of course, if you just only need a state, you can

The judgment is executed. Here is a few functions. One is a caller. He is responsible for the actual call command

One is a recipient. He is responsible for the effect of indicating the execution of the command. So the last is the command itself.

That is, the actual work. The relationship between them is. Customer call command through the caller. Command is executed

Return to the execution. At the same time, the command has a transaction. If the execution situation is not successful to restore the origin.

The customer judges the specific status by executing the situation.

Then I still assume a specific situation. I am planning to use the graphical interface because there is no universal

Sex. And the Command mode does not have to be used in the graphical interface. Suppose the customer wants to apply for a number

Is the number that cannot be 3 or 3 times. Let's simulate the specific situation.

// Conquer the interface icommand {bool state {get; set;} // Record transaction state int execute (); void unExecute (); // guarantee transaction rollback}

Public class number: iCommand {private bool state = false; // transaction status public bool state {get {return statne;} set {state = value;}} public int execute;}} public int execute;}} THIS.R = fr; // Specify a command recipient Random Rd = new randmo (); RD.Nextdouble () * 100); this.r.show (revALUE); // Present Specific return revALUE;} public void unExecute () {state = false; // state rollback}}

// Construct the receiver interface IRECEIVER {} public class receiver: IRECEIVER {public void show (int number) {Console.writeline ("The serial number of your application is:" number);}}

// The caller (caller maintenance), the caller here is quite active customer agent.

Public class invoker {private iCommand Command; private IRECEIVER Receiver; // is responsible for the specific representation by the recipient

// Load the actual command public void installcommand (iCommand C) {this.command = C;} // Call the actual function PUBLIC INVOKEREXECUTE (IRECEIVER R) {rollback: int Number = this.command.execute (); if (Number% 3) // is the multiple of 3 {this.command.unexecute (); goto rollback; // transaction rollback} else {r.show (number);}}} // Customer call public class client {public static int main (String [] args) {icommand command = new number (); IRECEVER R = new receiver (); infoker i = new invoker (); I.installCommand (c); // Loading I.InvokeRexecute (r); / / Means execution returnographic;}}

Actually. Customers can put any commands. The customer's representation can be any. That is to say

The caller is only responsible. The maintenance of the transaction and puts the command to the specific recipient. If it is an interface

Command mode in the middle. Then the caller is the package of the function pointer. Or event agent or event

Listener.

转载请注明原文地址:https://www.9cbs.com/read-27419.html

New Post(0)