资源简介
命令行模式的C++实现
编译环境VS2010
命令模式解析:http://blog.csdn.net/zs634134578/article/details/21031509
代码片段和文件信息
#include “command.h“
/*
* Phone类的成员函数实现
*/
void Phone::setCommand( Command* command) {
this->_command = command;
}
void Phone::runCommand() {
this->_command->execute();
}
/*
* 命令实际执行者,包括CPU,声卡
*/
Processor::Processor(){ }
void Processor::unlockScreen() {
std::cout << “解锁屏幕“ << std::endl << std::endl;
}
void Processor::startApp() {
std::cout << “启动应用程序...“ << std::endl;
std::cout << “启动应用程序成功“ << std::endl << std::endl;
}
void Processor::lockScreen() {
std::cout << “锁定屏幕 ... OK“ << std::endl << std::endl;
}
SoundCard::SoundCard() { }
void SoundCard::decreaseSound()
{
std::cout << “调低音量 ... OK“ << std::endl << std::endl;
}
void SoundCard::incraseSound()
{
std::cout << “提高音量 ... OK“ << std::endl << std::endl;
}
/*
* 命令子类,执行具体的命令
*/
LockScreenCommand::LockScreenCommand(Processor* processor) {
this->_processor = processor;
}
void LockScreenCommand::execute() {
this->_processor->lockScreen();
}
UnlockScreenCommand::UnlockScreenCommand(Processor* processor) {
this->_processor = processor;
}
void UnlockScreenCommand::execute() {
this->_processor->unlockScreen();
}
StartAppCommand::StartAppCommand(Processor* processor) {
this->_processor = processor;
}
void StartAppCommand::execute () {
this->_processor->startApp();
}
IncSoundCmd::IncSoundCmd(SoundCard* soundcard) {
this->soundcard = soundcard;
}
void IncSoundCmd::execute() {
this->soundcard->incraseSound();
}
DecSoundCmd::DecSoundCmd(SoundCard* soundcard) {
this->soundcard = soundcard;
}
void DecSoundCmd::execute() {
this->soundcard->decreaseSound();
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1718 2014-03-11 19:00 command.cpp
文件 1538 2014-03-11 19:00 command.h
文件 191 2014-03-11 19:01 main.cpp
文件 1481 2014-03-11 19:00 user.cpp
文件 265 2014-03-11 18:44 user.h
- 上一篇:郁闷的出纳员伸展树 C语言
- 下一篇:C++实验报告.doc
评论
共有 条评论