The following roles are available in the command pattern:
(1) Caller (invoker)
(2) Command receiver (receiver)
(3) clients (client)
(4) Command object
1 Public InterfaceCommand {2 Public voidexecute ();3 }4 Public classConcretecommandImplementsCommand {5 6 PrivateReceiver receiver =NULL;7 PrivateString State;8 9 PublicConcretecommand (receiver receiver) {Ten This. Receiver =receiver; One } A Public voidExecute () { - receiver.action (); - } the } - - - Public classReceiver { + Public voidaction () { - //function code that actually executes the command operation + } A } at - Public classInvoker { - PrivateCommand command =NULL; - - Public voidsetcommand (Command command) { - This. Command =command; in } - to Public voidRunCommand () { + Command.Execute (); - } the } * $ Public classClient {Panax Notoginseng Public voidAssemble () { - //Create a recipient theReceiver receiver =NewReceiver (); + //Create a Command object, set its recipient ACommand command =NewConcretecommand (receiver); the //Create a invoker and set the Command object in +Invoker Invoker =NewInvoker (); - invoker.setcommand (command); $ } $}
In netd command mode, both the client role and the invoker role are Commandlistener
Receiver is a variety of controllers in the Commandlistener, including
Firewallcontroller *commandlistener::sfirewallctrl = NULL;
Unlike the command pattern above, the various commands are Commandlistener internal classes that can be used directly with receiver without passing receiver to the Command object. A different point is that the various controllers here as receiver do not have the same action function as the example, but are directly in the RunCommand function (example is the Execute function of the command Class) Use the controller to implement various actions.
The various command distribution paths for NETD are as follows:
Socketlistener::runlistener
->fameworklistener::ondataavailable
-Fameworklistener::d Ispatchcommand
-Commandlistener:: Various Cmd::runcommand
(All rights reserved, reprint please inform)
[Design mode] Command design mode in NETD, listener mode in Networkmanagementservice