prototype 模式结构图:
实现:
1 #ifndef _PROTOTYPE_H_ 2 #define _PROTOTYPE_H_ 3 4 class Prototype 5 { 6 public: 7 virtual ~Prototype(); 8 virtual Prototype* Clone() const = 0; 9 10 protected:11 Prototype();12 13 private:14 };15 16 class ConcretePrototype:public Prototype17 {18 public:19 ConcretePrototype();20 ConcretePrototype(const ConcretePrototype& cp);21 ~ConcretePrototype();22 Prototype* Clone()const;23 protected:24 private:25 };26 27 #endif
1 #include "Prototype.h" 2 #include3 using namespace std; 4 5 Prototype::Prototype() 6 { 7 8 } 9 Prototype::~Prototype()10 {11 12 }13 Prototype* Prototype::Clone()const14 {15 return 0;16 }17 ConcretePrototype::ConcretePrototype()18 {19 20 };21 ConcretePrototype::~ConcretePrototype()22 {23 24 }25 ConcretePrototype::ConcretePrototype(const ConcretePrototype& cp)26 {27 cout<<"ConcretePrototype copy..."<