vendredi 10 mars 2017

How to implement "Registry pattern" in C++, using single registry for many interface implementation

Let a virtual pure class Interface and two concrete implementation InterfaceImplA and InterfaceImplB.

I want to have a registry where i can register various implementations of Interface. This registry must be able to create instances of my concrete types, using an arbitrary identifier (QString, std::string..).

A sample application would be like :

  Registry<Interface> registry;
  registry.register<InterfaceImplA>("A");
  registry.register<InterfaceImplB>("B");
  InterfaceImplA* instanceA = registry.create("A");
  InterfaceImplB* instanceB = registry.create("B");

Aucun commentaire:

Enregistrer un commentaire