I'm trying to develop a business application in C++. I want to be able to build a framework of the business objects which can be extended later without touching the framework source.
My main problem (one of them anyway) has been designing a way for these objects to be persistent. I want to use a relational database product. The headache comes from being able to do polymorphic reads of the data from the database.
I have made various attempts to design a way around this but have just been running around in circles with factories, abstract factories etc and still no luck. I have read in some books about virtual constructors which I hoped would do it for me but no luck either.
Problem Description --------------------
If have a class hierarchy of classes that looks like this.
I want to be able to load from the database from any node in the hierarchy and have it polymorphically load the correct object types. E.g. If I load all animals from the database I want the set to contain instances of Reptiles, Fish, Insect as appropriate. I also want to be able to go down the hierarchy and load all instances of Vertebrates and have it load the correct instances of its subclasses.
Many of the solutions I've seen require the supertype to know of its subtypes and sometimes even requires instantiating an instance of a factory instance of each of the types even if it may not be used.
I want the superclasses to be built into a framework like for example a biology framework or accounting framework. Applications built on the framework would now extend the framework by creating new subclasses of the classes provided in the framework. In this situation it is not possible to go and modify the factory classes in the framework.
I hope someone can help me with a solution to this problem.