Command
#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的更多相关文章
- ifconfig: command not found(CentOS专版,其他的可以参考)
ifconfig: command not found 查看path配置(echo相当于c中的printf,C#中的Console.WriteLine) echo $PATH 解决方案1:先看看是不是 ...
- scp报错 -bash: scp: command not found
环境:RHEL6.5 使用scp命令报错: [root@oradb23 media]# scp /etc/hosts oradb24:/etc/ -bash: scp: command not fou ...
- ENode框架单台机器在处理Command时的设计思路
设计目标 尽量快的处理命令和事件,保证吞吐量: 处理完一个命令后不需要等待命令产生的事件持久化完成就能处理下一个命令,从而保证领域内的业务逻辑处理不依赖于持久化IO,实现真正的in-memory: 保 ...
- 设计模式(六):控制台中的“命令模式”(Command Pattern)
今天的博客中就来系统的整理一下“命令模式”.说到命令模式,我就想起了控制台(Console)中的命令.无论是Windows操作系统(cmd.exe)还是Linux操作系统(命令行式shell(Comm ...
- GET command找不到
谷歌的: On running a cronjob with get command, I was getting the following error. /bin/sh: GET: command ...
- source /etc/profile报错-bash: id:command is not found
由于误操作导致 source /etc/profile 报错 -bash: id:command is not found 此时,linux下很多命令到不能能用,包括vi ls 等... 可以使用 e ...
- Webform(七)——内置对象(Session、Application)和Repeater的Command操作
内置对象:用于页面之间的数据交互 为什么要使用这么内置对象?因为HTTP的无状态性. 一.内置对象 (一)Session 跟Cookies一样用来存储用户数据 1.Session.Cookies对比 ...
- 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 是因为目标板的芯片处于休眠 ...
- mac 修改command+q 退出
实在受不了! 在chrome中command+w 是关闭当前页面,command+q 退出浏览器: 经常查阅资料打开了N多个窗口,关闭时不小心将command+q当command+w按: so ... ...
- Ubuntu中配置Java环境变量时,出现command not found问题解决记录
百度出Ubuntu中配置Java环境变量时,在利用sudo gedit /etc/profile 对profile编辑后, 在terminal中输入 sudo source /etc/profile, ...
随机推荐
- Web性能压力测试工具之Apache AB 详解
下载安装地址: http://httpd.apache.org/download.cgi yum install httpd-tools http://www.apachelounge.com/dow ...
- WebService中实现上传下载文件
不多说,直接看代码: /*上传文件的WebService*/ using System; using System.Collections; using System.Collections.Gene ...
- C语言中fseek函数
C语言fseek()函数:用来设定文件的当前读写位置 头文件: #include <stdio.h> 定义函数: int fseek(FILE * stream, long offset, ...
- 解决insmod: error inserting 'hello.ko': -1 Invalid module format
编译自己的内核模块后,insmod出现error:error inserting 'hello.ko': -1 Invalid module format 出现这种情况的原因是因为Makefile种使 ...
- springmvc 注解 RequestParam/RequestHeader/CookieValue
RequestParam注解: 示例: @RequestMapping("/testRequestParam") public String testRequestParam(@R ...
- [POJ 1635] Subway tree systems (树哈希)
题目链接:http://poj.org/problem?id=1635 题目大意:给你两棵树的dfs描述串,从根节点出发,0代表向深搜,1代表回溯. 我刚开始自己设计了哈希函数,不知道为什么有问题.. ...
- javaSE学习博客与笔记
equals和==的区别 Java中equals和==的区别 java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,do ...
- threading event
#!usr/bin/env python 2 #coding: utf-8 3 #Author: Andy 4 5 import threading 6 import time 7 8 def pro ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem L
Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...