/** * command.h * Implemented by Blueprint Technologies, Inc. */ #ifndef _command_h #define _command_h /** * Declares an interface for executing an operation. */ class Command { public: virtual void execute() = 0; }; /** * Knows how to perform the operations associated with * carrying out a request. Any class may serve as a Receiver. */ class Receiver { public: virtual void action() { }; }; /** * Defines a binding between a Receiver object and an * action. Implements 'execute' by invoking the corresponding * operation on Receiver. */ class ConcreteCommand: public Command { private: Receiver* receiver; public: ConcreteCommand(): Command(), receiver(0) { }; virtual void execute() { receiver -> action(); }; Receiver* getReceiver() { return receiver; }; void setReceiver( Receiver* receiver ) { this -> receiver = receiver; }; }; /** * Asks the command to carry out the request. */ class Invoker { private: Command* command; public: Invoker(): command(0) {}; void invoke() { if( command ) { command -> execute(); } }; Command* getCommand() { return command; }; void setCommand( Command* command ) { this -> command = command; } }; #endif