设计模式 - Flyweight
2013-05-05 16:56
176 查看
意图:运用共享技术有效地支持大量细粒度的对象。
class Flyweight { public: Flyweight() {} virtual ~Flyweight() {} virtual void Operation(int extrinsic_state) = 0; }; class ConcreteFlyweight: public Flyweight { public: ConcreteFlyweight(const string& key) { this->key = key; } ~ConcreteFlyweight() {} void Operation(int extrinsic_state) { cout<<"ConcreteFlyweight::Operation()"<<endl; } private: string key; }; class FlyweightFactory { public: FlyweightFactory() {} ~FlyweightFactory() {} Flyweight* GetFlyweight(const string& key) { if(flyweightMap.find(key) == flyweightMap.end()) { flyweightMap[key] = new ConcreteFlyweight(key); } return flyweightMap[key]; } private: map<string, Flyweight*> flyweightMap; };
相关文章推荐
- 设计模式:享元模式(Flyweight)
- 设计模式之享元模式(Flyweight)摘录
- 【设计模式攻略】结构型模式之Flyweight 模式
- php设计模式 FlyWeight (享元模式)
- 23种设计模式(10)--Flyweight模式
- 设计模式之Flyweight(享元) FlyWeight模式
- [设计模式笔记]二. 结构型模式--12.Flyweight模式(享元模式)(一)
- 设计模式21---设计模式之享元模式(Flyweight)(结构型)
- 设计模式学习日志(12)-Flyweight享元(结构型模式)
- 设计模式之享元模式(Flyweight)
- 设计模式 http://www.runoob.com/design-pattern/flyweight-pattern.html
- C++ 设计模式(八) FlyWeight模式
- 笔记:Gof设计模式--Flyweight
- 【设计模式】结构型模式之Flyweight
- 【设计模式】之十七Flyweight
- 设计模式学习笔记之Flyweight模式(享元模式)
- 结构型设计模式---享元模式(Flyweight)
- java 23种常用设计模式之享元模式(FlyWeight)
- java设计模式-亨元模式(Flyweight)
- 设计模式(十)享元模式Flyweight(结构型)