C++/0x01-design pattern13 proxy pattern proxy pattern 1. case 1 #include #include using namespace std; class Person { public: string nameString; static string list[]; static int next; public: Person() { nameString = list[next++]; } string name() { return nameString; } }; string Person::list[] = { "Tom", "Dick", "Harry", "Bubba" }; int Person::next = 0; class PettyCashProtected { public: int balance; public: PettyCashProtected() { bala.. 2016. 7. 18. Flyweight pattern Flyweight pattern 1.소스 #include #include #include #include using namespace std; class Icon { public: Icon(char *fileName) { strcpy(_name, fileName); if (!strcmp(fileName, "go")) { _width = 20; _height = 20; } if (!strcmp(fileName, "stop")) { _width = 40; _height = 40; } if (!strcmp(fileName, "select")) { _width = 60; _height = 60; } if (!strcmp(fileName, "undo")) { _width = 30; _height = 30; } }.. 2016. 7. 18. facade pattern facade pattern 1.소스 #include using namespace std; class MisDepartment { public: void submitNetworkRequest() { _state = 0; } bool checkOnStatus() { _state++; if (_state == Complete) return 1; return 0; } private: enum States { Received, DenyAllKnowledge, ReferClientToFacilities, FacilitiesHasNotSentPaperwork, ElectricianIsNotDone, ElectricianDidItWrong, DispatchTechnician, SignedOff, DoesNotWork,.. 2016. 7. 14. decorator pattern. decorator pattern 1.소스 #include using namespace std; class I { public: virtual ~I(){} virtual void do_it() = 0; }; class A: public I { public: ~A() { cout 2016. 7. 14. 이전 1 2 3 4 다음