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");
It will be used as as part of a data model serialisation/deserialization component, where the serialized object uses only the interface, but serialized instances may use various implementation.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…