设计模式之 命令模式
class Receiver { public: Receiver(void); ~Receiver(void); public: void run(void); void stop(void); }; class Command { public: virtual ~Command(void); virtual void execute(void) = 0; private: Receiver *receiver_; }; class Run: public Command { public: Run(Receiver *pReceiver); ~Run(void); public: virtual void execute(void) { receiver_->run(); } }; class Stop: public Command { public: Stop(Receiver *pReceiver); ~Stop(void); public: virtual void execute(void) { receiver_->stop(); } }; class Invoker { public: Invoker(void); ~Invoker(void); public: void addCommand(Command *pCommand); void execute(void); private: vector<Command*> commandList_; };