Command mode

xiaoxiao2021-03-06  62

Class Command

{

// fields

Private Var Receiver: Receiver;

// conntructors

Private function command (receiver: receiver)

{

This.Receiver = Receiver;

}

//Methods

PUBLIC FUNCTION EXECUTE (): void {};

}

// "Receiver"

Class Receiver

{

//Methods

Public function action (): void

{

"" Called received () ");

}

}

// "Invoker"

Class Invoker

{

// fields

Private var command: Command;

//Methods

Public Function SetCommand (Command: Command): Void

{

this.command = Command;

}

Public function executeCommand (): void

{

Command.execute ();

}

}

// "ConcreteCommand"

Class ConcreteCommand Extends Command

{

// conntructors

Public Function ConcreteCommand (Receiver: Receiver)

{

Super (Receiver);

}

//Methods

Public function execute (): void

{

Receiver.Action ();

}

}

//client.fla

// Create Receiver, Command, And Invoker

Var r: receiver = new receiver ();

Var c: command = new concreteCommand (R);

VAR i: invoker = new invoker ();

// SET and Execute Command

I.setCommand (C);

I.executeCommand ();

// caled receiver.Action ()

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

New Post(0)