FLYWEIGHT 플라이급 패턴 (분동 패턴)
- 공유를 통해 많은 작은 객체들을 지원 한다.
- 메모리 절약에 용의 하다.
- BTree , map 이용
#include <iostream>
#include <map> using namespace std; class Flyweight{ public: virtual void operation() = 0; }; class UnsharedConcreteFlyweight : public Flyweight{ public: void operation() override { cout << "Unshared" << endl; } }; class ConcreteFlyweight : public Flyweight{ public: void operation() override { cout << "Share" << endl; } }; class FlyweightFactory{ public: Flyweight* getFlyweight(int key){ if(_map.find(key) == _map.end()){ _map[key] = new ConcreteFlyweight; } return _map[key]; } private: map<int,Flyweight*> _map; }; int main(){ FlyweightFactory factory; Flyweight* _flyweight = factory.getFlyweight(1); _flyweight->operation(); return 0; }'Study > Design Patterns c++' 카테고리의 다른 글
Design Patterns ABSTRACT FACTORY 추상 팩토리 패턴 C++ (0) | 2018.07.03 |
---|---|
Design Patterns PROXY 프록시 패턴 C++ (0) | 2018.07.02 |
Design Patterns FACADE 퍼사드 패턴 C++ (0) | 2018.06.19 |
Design Patterns DECORATOR 장식자 패턴 C++ (0) | 2018.06.19 |
Design Patterns STRATEGY 전략 패턴 C++ (0) | 2018.06.18 |