#include <iostream>

using namespace std;
#define DESTROY_POINTER(ptr) if (ptr) { delete ptr; ptr = NULL; } class Receiver
{
public:
void Action1() { cout<<"Receiver::Action1"<<endl; }
void Action2() { cout<<"Receiver::Action2"<<endl; }
void Action3() { cout<<"Receiver::Action3"<<endl; }
}; class Command
{
public:
Command(Receiver* pReceiver) { m_pReceiver = pReceiver; }
virtual ~Command() { DESTROY_POINTER(m_pReceiver); } virtual void Execute()=; protected:
Receiver* m_pReceiver;
}; class ConcreteCommandA : public Command
{
public:
ConcreteCommandA(Receiver* pReceiver) : Command(pReceiver) {} virtual void Execute() { m_pReceiver->Action1(); }
}; class ConcreteCommandB : public Command
{
public:
ConcreteCommandB(Receiver* pReceiver) : Command(pReceiver) {}
virtual void Execute() { m_pReceiver->Action2(); }
}; class ConcreteCommandC : public Command
{
public:
ConcreteCommandC(Receiver* pReceiver) : Command(pReceiver) {}
virtual void Execute() { m_pReceiver->Action3(); }
}; class Invoker
{
public:
Invoker(Command* pCommand) { m_pCommand = pCommand; }
~Invoker() { DESTROY_POINTER(m_pCommand); } void Request() { m_pCommand->Execute(); } private:
Command* m_pCommand;
}; int main(int argc, char *argv[])
{
Receiver* pReceiver = new Receiver; Invoker invoker1(new ConcreteCommandA(pReceiver));
invoker1.Request(); Invoker invoker2(new ConcreteCommandB(pReceiver));
invoker2.Request(); Invoker invoker3(new ConcreteCommandC(pReceiver));
invoker3.Request(); return ;
}

Command的更多相关文章

  1. ifconfig: command not found(CentOS专版,其他的可以参考)

    ifconfig: command not found 查看path配置(echo相当于c中的printf,C#中的Console.WriteLine) echo $PATH 解决方案1:先看看是不是 ...

  2. scp报错 -bash: scp: command not found

    环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...

  3. ENode框架单台机器在处理Command时的设计思路

    设计目标 尽量快的处理命令和事件,保证吞吐量: 处理完一个命令后不需要等待命令产生的事件持久化完成就能处理下一个命令,从而保证领域内的业务逻辑处理不依赖于持久化IO,实现真正的in-memory: 保 ...

  4. 设计模式(六):控制台中的“命令模式”(Command Pattern)

    今天的博客中就来系统的整理一下“命令模式”.说到命令模式,我就想起了控制台(Console)中的命令.无论是Windows操作系统(cmd.exe)还是Linux操作系统(命令行式shell(Comm ...

  5. GET command找不到

    谷歌的: On running a cronjob with get command, I was getting the following error. /bin/sh: GET: command ...

  6. source /etc/profile报错-bash: id:command is not found

    由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...

  7. Webform(七)——内置对象(Session、Application)和Repeater的Command操作

    内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. 一.内置对象 (一)Session 跟Cookies一样用来存储用户数据 1.Session.Cookies对比 ...

  8. MDK st-link下载STM32程序出现Internal command error和Error:Flash download failed. Target DLL

    MDK st-link下载STM32程序出现Internal command error和Error:Flash download failed. Target DLL   是因为目标板的芯片处于休眠 ...

  9. mac 修改command+q 退出

    实在受不了! 在chrome中command+w 是关闭当前页面,command+q 退出浏览器: 经常查阅资料打开了N多个窗口,关闭时不小心将command+q当command+w按: so ... ...

  10. Ubuntu中配置Java环境变量时,出现command not found问题解决记录

    百度出Ubuntu中配置Java环境变量时,在利用sudo gedit /etc/profile 对profile编辑后, 在terminal中输入 sudo source /etc/profile, ...

随机推荐

  1. Python & MapReduce

    使用Python实现Hadoop MapReduce程序 原文请参考: http://blog.csdn.net/zhaoyl03/article/details/8657031/ 下面只是将mapp ...

  2. ruby字符串学习笔记5

    1获取字符串某部分 s = "My kingdom for a string!" s.slice(3,7) # kingdom s[3,7] # kingdom s[/.ing/] ...

  3. [ActionScript 3.0] 自定义顶级类

    为了结合FlashBuilder编译参数,达到发布项目时不编译trace代码方便,写一个顶级类: package { public function tracing(...args):void { C ...

  4. [Flex] PopUpButton系列 —— 判断下拉列表是否选中

    <?xml version="1.0" encoding="utf-8"?> <!--Flex中如何利用dataDescriptor属性和is ...

  5. linux双机GFS的配置

    1.两台服务器安装如下包: apr-1.2.7-11.el5_3.1.x86_64.rpmapr-util-1.2.7-11.el5.x86_64.rpmcman-2.0.115-34.el5.x86 ...

  6. PL/SQL Developer使用技巧、快捷键

    1.类SQL PLUS窗口:File->New->Command Window,这个类似于oracle的客户端工具sql plus,但比它好用多了. 2.设置关键字自动大写:Tools-& ...

  7. 如何实现Oracle修改用户权限 .

    这里将介绍Oracle修改用户权限的实现过程,包括一些权限管理方面的东西.希望通过本文能对大家了解Oracle修改用户权限有所帮助. ORACLE数据库用户与权限管理 ORACLE是多用户系统,它允许 ...

  8. threading event

    #!usr/bin/env python 2 #coding: utf-8 3 #Author: Andy 4 5 import threading 6 import time 7 8 def pro ...

  9. iptable怎么用?

    iptables -A FORWARD -s 10.0.0.0/8  -p tcp  --dport  80  -j DROP [拒绝转发来自10.0.0.0/8网段,目的端口是80的数据包]

  10. 2014款Macbook Air安装单独X64 Win7系统

    之所以写出来,是因为网上大多是用BootCamp安装双系统的,安装单独Win7的教程少之又少,然后大多数还写得不清不楚,所以折腾了一阵子.其实装好之后,还是觉得挺简单的. 我主要参考了两篇文章,链接如 ...