设计模式之 命令模式

 

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_;
};

 

posted on 2015-07-30 18:08  霏霏暮雨  阅读(169)  评论(0编辑  收藏  举报

导航