C++/0x01-design pattern13 Chain of Responsibility Chain of Responsibility 1.소스 결과 https://youtu.be/EhGncgSg2wg 2016. 7. 18. Prototype Prototype 1.소스 #include using namespace std; enum imageType { LSAT, SPOT }; class Image { public: virtual void draw() = 0; static Image *findAndClone(imageType); protected: virtual imageType returnType() = 0; virtual Image *clone() = 0; // As each subclass of Image is declared, it registers its prototype static void addPrototype(Image *image) { _prototypes[_nextSlot++] = image; } private: // add.. 2016. 7. 18. Factory Method Factory Method 1.소스 #include #include #include using namespace std; /* Abstract base class declared by framework */ class Document { public: Document(char *fn) { strcpy(name, fn); } virtual void Open() = 0; virtual void Close() = 0; char *GetName() { return name; } private: char name[20]; }; /* Concrete derived class defined by client */ class MyDocument: public Document { public: MyDocument(cha.. 2016. 7. 18. builder pattern builder pattern 1.소스 #include #include #include #include using namespace std; enum PersistenceType { File, Queue, Pathway }; struct PersistenceAttribute { PersistenceType type; char value[30]; }; class DistrWorkPackage { public: DistrWorkPackage(char *type) { sprintf(_desc, "Distributed Work Package for: %s", type); } void setFile(char *f, char *v) { sprintf(_temp, "\n File(%s): %s", f, v); strc.. 2016. 7. 18. 이전 1 2 3 4 다음