• 设计模式命令实现C++


    /*********************************
    *设计模式--命令实现
    *C++语言
    *Author:WangYong
    *Blog:http://www.cnblogs.com/newwy
    ********************************/
    #include <iostream>
    using namespace std;
    class Reciever
    {
    	public:
    	Reciever(){}
    	~Reciever(){}
    	void Action(){cout<<"Reciever action.."<<endl;}
    };
    class Command
    {
    	public:
    	Command(){}
    	virtual ~Command(){};
    	virtual void Exute() = 0;
    	
    };
    class ConcreteCommand:public Command
    {
    	public:
    	ConcreteCommand(Reciever * rev){this->_rev = rev;}
    	~ConcreteCommand(){delete this->_rev;}
    	void Excute(){_rev->Action();cout<<"ConcreteCommand...."<<endl;}
    	private:
    	Reciever *_rev;
    };
    class Invoker
    {
    	public:
    	Invoker(Command *cmd){_cmd = cmd;}
    	~Invoker(){delete _cmd;}
    	void Invoke(){_cmd->Exute();}
    	protected:
    	Command *_cmd;
    };
    int main()
    {
    	Reciever *rev = new Reciever();
    	Command *cmd = new ConcreteCommand(rev);
    	Invoker *inv = new Invoker(cmd);
    	inv->Invoke();
    	return 0;
    }
    
    
  • 相关阅读:
    PHP 学习轨迹
    beego 遇到的一些问题
    Fiddler 502问题
    SourceTree
    Trait
    PHP PSR 标准
    解决MySQL联表时出现字符集不一样
    Git 代码管理命令
    PHP 运行相关概念
    CentOS 7
  • 原文地址:https://www.cnblogs.com/newwy/p/1855207.html
Copyright © 2020-2023  润新知