Flyweight 设计模式
来源:互联网 发布:网络拓扑结构图软件 编辑:程序博客网 时间:2024/06/06 18:50
#include<iostream>#include<string>#include<vector>using namespace std;class Flyweight{public:virtual ~Flyweight(){};virtual void Operation(const string& extrinsicState) {};string GetintrinsicSate() {return _intrinsicState;};protected:Flyweight(string intrinsicState) { this->_intrinsicState=intrinsicState;};//注意在这里Protectedprivate:string _intrinsicState;};class ConcreteFlyweight: public Flyweight{public:ConcreteFlyweight(string intrinsicSate):Flyweight(intrinsicSate) {};virtual ~ConcreteFlyweight() {};virtual void Operation(const string& extrinsicState){cout<<GetintrinsicSate()<<endl;cout<<extrinsicState<<endl; }};class UnshareConcreteFlyweight: public Flyweight{public:UnshareConcreteFlyweight(string extr):Flyweight(extr){};virtual ~UnshareConcreteFlyweight(){};virtual void Operation(const string& extrinsicState){cout<<extrinsicState<<endl;}};class FlyweightFactory{public:FlyweightFactory(){};~FlyweightFactory(){};Flyweight* GetFactory(string key){vector<Flyweight*>::iterator iter=this->_fly.begin();for(;iter!=this->_fly.end();++iter){if((*iter)->GetintrinsicSate()==key){cout<<"Object have ready"<<endl;return *iter;}}Flyweight* fly=new ConcreteFlyweight(key); // 注意是ConCreteFlyweightthis->_fly.push_back(fly);return fly;}private:vector<Flyweight*> _fly;};int main(int argc, char* argv[]){FlyweightFactory* fc=new FlyweightFactory();Flyweight* ef=fc->GetFactory("Hello");Flyweight* cc=fc->GetFactory("Moargan");Flyweight* cd=fc->GetFactory("Hello"); cd->Operation("job"); Flyweight* fcd= new UnshareConcreteFlyweight("My English"); fcd->Operation("test"); return 0;}
0 0
- 设计模式 - Flyweight模式
- 设计模式--FlyWeight 模式
- 设计模式-- Flyweight
- Flyweight设计模式
- 设计模式之 flyweight
- Flyweight设计模式
- 设计模式-FlyWeight
- 设计模式11 - Flyweight
- JAVA设计模式-FlyWeight
- 设计模式之FlyWeight
- Flyweight 设计模式
- Structual设计--Flyweight模式
- 设计模式之FlyWeight
- 设计模式之Flyweight
- c++ FlyWeight 设计模式
- 设计模式之FlyWeight模式
- 设计模式学习11 Flyweight
- java设计模式10:Flyweight
- MFC的CListBox控件使用LBS_OWNERDRAWVARIABLE风格不能AddString的问题
- 变量 地址 值
- MySQL数据库常用操作语句大全
- 设计模式 - 代理模式(proxy pattern) 未使用代理模式 详解
- Caused by: java.lang.ClassNotFoundException: org.jbpm.pvm.internal.processengine.SpringHelper
- Flyweight 设计模式
- C++ 四则运算
- ubuntu12.04 64bit 安装nodeJS
- sphinx 增量索引 实现近实时更新
- linux shell 脚本命令操作案例大全
- sublime text如何安装ctags来定位函数
- 详解YUV数据格式
- 修改maven本地仓库的位置及疑惑
- Struts2多个文件上传的分析及源代码说明