#include <iostream>
using namespace std;
class State;
class ConcreteStateB;
class ConcreteStateA;
class State {
public:
virtual void OperationChangeState(Context*) = 0;
virtual void OperationInterface(Context*) = 0;
virtual ~State() { }
protected:
bool ChangeState(Context* con, State *st) {
con->ChangeState(st);
}
};
class ConcreteStateA :public State {
public:
void OperationChangeState(Context* con) {
OperationInterface(con);
this->ChangeState(con, new ConcreteStateB());
}
void OperationInterface(Context* con) {
cout << "ConcreteStateA::OperationInterface..." << endl;
}
};
class ConcreteStateB :public State {
public:
void OperationChangeState(Context* con) {
OperationInterface(con);
this->ChangeState(con, new ConcreteStateA());
}
void OperationInterface(Context* con) {
cout << "ConcreteStateB::OperationInterface..." << endl;
}
};
class Context {
public:
Context(State* st) {
_st = st;
}
void OperationInterface() {
_st->OperationInterface(this);
}
void OperationChangeState() {
_st->OperationInterface(this);
}
private:
friend class State;
bool ChangeState(State* st) {
_st = st;
return true;
}
State *_st;
};
int main() {
State *st = new ConcreteStateA();
Context *con = new Context(st);
con->OperationInterface();
con->OperationInterface();
con->OperationInterface();
delete con;
delete st;
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
23种设计模式的C++实现
共86个文件
cpp:29个
vcxproj:23个
filters:23个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 174 浏览量
2023-08-26
15:39:29
上传
评论
收藏 83KB ZIP 举报
温馨提示
23种设计模式的C++实现
资源推荐
资源详情
资源评论
收起资源包目录
DesignPattern-master.zip (86个子文件)
DesignPattern-master
MediatorPattern
MediatorPattern.cpp 2KB
MediatorPattern.vcxproj.filters 935B
MediatorPattern.vcxproj 4KB
AdapterPattern
AdapterPattern.vcxproj 4KB
AdapterPattern.vcxproj.filters 934B
AdapterPattern.cpp 674B
IteratorPattern
IteratorPattern.cpp 331B
Aggregate.h 461B
IteratorPattern.vcxproj.filters 1KB
IteratorPattern.vcxproj 4KB
Iterator.h 468B
Aggregate.cpp 556B
Iterator.cpp 463B
MementoPattern
MementoPattern.cpp 1KB
MementoPattern.vcxproj.filters 934B
MementoPattern.vcxproj 4KB
BridgePattern
BridgePattern.vcxproj.filters 933B
BridgePattern.cpp 946B
BridgePattern.vcxproj 4KB
VisitorPattern
VisitorPattern.vcxproj.filters 1KB
Element.cpp 389B
Visitor.cpp 591B
VisitorPattern.cpp 255B
Element.h 326B
VisitorPattern.vcxproj 4KB
Visitor.h 535B
FlyweightPattern
FlyweightPattern.vcxproj 4KB
FlyweightPattern.cpp 1KB
FlyweightPattern.vcxproj.filters 936B
SingletonPattern
SingletonPattern.vcxproj.filters 936B
SingletonPattern.vcxproj 4KB
SingletonPattern.cpp 584B
FactoryPattern
FactoryPattern.vcxproj 4KB
FactoryPattern.cpp 945B
FactoryPattern.vcxproj.filters 934B
TemplatePattern
TemplatePattern.cpp 1KB
TemplatePattern.vcxproj 4KB
TemplatePattern.vcxproj.filters 935B
LICENSE 18KB
PrototypePattern
PrototypePattern.cpp 766B
PrototypePattern.vcxproj.filters 936B
PrototypePattern.vcxproj 4KB
ProxyPattern
ProxyPattern.vcxproj 4KB
ProxyPattern.cpp 628B
ProxyPattern.vcxproj.filters 932B
InterpreterPattern
InterpreterPattern.vcxproj.user 162B
InterpreterPattern.vcxproj.filters 938B
InterpreterPattern.vcxproj 4KB
InterpreterPattern.cpp 1KB
CompositePattern
CompositePattern.cpp 1KB
CompositePattern.vcxproj 4KB
CompositePattern.vcxproj.filters 936B
FacadePattern
FacadePattern.vcxproj 4KB
FacadePattern.cpp 712B
FacadePattern.vcxproj.filters 933B
StatePattern
StatePattern.vcxproj 4KB
StatePattern.cpp 2KB
StatePattern.vcxproj.filters 932B
ObserverPattern
Observer.cpp 585B
Subject.cpp 496B
ObserverPattern.cpp 346B
ObserverPattern.vcxproj 4KB
Observer.h 549B
ObserverPattern.vcxproj.filters 1KB
Subject.h 597B
AbstractFactoryPattern
AbstractFactoryPattern.vcxproj.filters 942B
AbstractFactoryPattern.cpp 1KB
AbstractFactoryPattern.vcxproj 4KB
DecoratorPattern
DecoratorPattern.vcxproj.filters 936B
DecoratorPattern.vcxproj 4KB
DecoratorPattern.cpp 972B
StrategyPattern
StrategyPattern.cpp 748B
StrategyPattern.vcxproj 4KB
StrategyPattern.vcxproj.filters 935B
.gitignore 38B
BuilderPattern
BuilderPattern.cpp 1KB
BuilderPattern.vcxproj 4KB
BuilderPattern.vcxproj.filters 934B
CommandPattern
CommandPattern.vcxproj 4KB
CommandPattern.vcxproj.filters 934B
CommandPattern.cpp 802B
DesignPattern.sln 11KB
ChainOfResponsibilityPattern
ChainOfResponsibilityPattern.cpp 1KB
ChainOfResponsibilityPattern.vcxproj.filters 948B
ChainOfResponsibilityPattern.vcxproj 4KB
DesignPattern.v12.suo 81KB
共 86 条
- 1
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6649
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
- MyBatis动态SQL.pdf
- 基于stm32单片机protues仿真的温湿度控制系统设计(仿真图、源代码)
- 词向量:自然语言处理的基石
- mybatis动态sql
- 40G微信小程序开发教程(工具插件+视频教程)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功