Design Pattern6 [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 다음