class AbstractItem { public: virtual AbstractItem* clone() = 0; //... };//class AbstractItem class RealItemA : public AbstractItem { public: virtual AbstractItem* clone(); //... };//class RealItemA class RealItemB : public AbstractItem { public: virtual AbstractItem* clone(); //... };//class RealItemB
Prototype details:
Provides mechanism for virtual construction.
Instantiation of prototypes is deferred:
new prototypes can be instantiated dynamically at runtime
it is possible to delete existing prototypes.
We might also consider maintaining a registry of prototypes:
std::map< std::string, AbstractItem* > item_registry;