Design Pattern --- Prototype
class Prototype { public: virtual Prototype *Clone() = 0; }; class PrototypeA : public Prototype { public: virtual Prototype *Clone() override { return new PrototypeA(*this); } }; class PrototypeB : public Prototype { public: virtual Prototype *Clone() override { return new PrototypeB(*this); } }; void foo(Prototype &p) { // Prototype 模式优势在于减少 Factory 模式引入的大量子类. Prototype *bar = p->Clone(); // ... // TODO: Release memory. }