Listing 2: Skeleton of a simple generic prototype factory class

template<typename Proto, typename Id>
class ProtoTypeFactory
{
public:
  void RegisterProtoType(Proto* pProtoType, Id id)
  { protoTypeCollection[id] = pProtoType; }
  
  Proto* GetClone(Id id)
  { return protoTypeCollection[id]->Clone(); }

private:
  std::map<Id, Proto*> protoTypeCollection;
};
— End of Listing —