码迷,mamicode.com
首页 > 其他好文 > 详细

设计模式之 命令模式

时间:2015-07-30 19:26:58      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

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

 

设计模式之 命令模式

标签:

原文地址:http://www.cnblogs.com/foreverstars/p/4690213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!