c++9 [C++ Design Pattern] Flyweight Flyweight 기법은 => 객체의 인스턴스를 공유해서 메모리 사용을 최적화 하는 기법이다. 걍 자원을 공유한다고 생각하면 될 것 같다. #include #include #include class Image { std::string image_url; public: Image(const std::string& url) : image_url(url) { std::cout 2023. 11. 30. [C++ Design Pattern] Adapter Adapter는 사실 중간자 역할을 해주는 간접층을 하나 생성하는 것이라고 생각하면 된다. #include #include #include class TextView { std::string data; public: TextView(const std::string& s) : data(s) {} void show() { std::cout 2023. 11. 30. [C++ Design Pattern] Composite Composite 패턴은 객체들을 트리 구조로 구성하여 개별 객체와 복합 객체(객체들의 집합)를 동일하게 취급할 수 있도록 하는 디자인 패턴인데, 객체들 간에 계층 구조를 만들어 트리로 표현하면서 개별 객체와 복합 객체를 일관성 있게 다룰 수 있게 도와줘. #include #include #include class Item { std::string name; public: Item(const std::string& name) : name(name) {} virtual ~Item() {} virtual int get_size() = 0; }; class File : public Item { int size; public: File(const std::string& name, int size) : Item(.. 2023. 11. 29. [C++ Design Pattern] Strategy Pattern strategy pattern(전략 패턴) template struct IAllocator { virtual T* allocate(int size) = 0; virtual void deallocate(T* p, int size) = 0; virtual ~IAllocator() {} }; template class vector { T* buff; IAllocator* ax; public: void set_allocator(IAllocator* p) { ax = p; } void resize(int n) { buff = ax->allocate(n); ax->deallocate(buff, n); } }; template class newAllocator : public IAllocator { public: T.. 2023. 11. 29. 이전 1 2 3 다음