The Artima Developer Community
Sponsored Link

C# Answers Forum
Persistence and Polymorphic Reads

2 replies on 1 page. Most recent reply: Sep 22, 2003 9:21 AM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Jide Ogundipe

Posts: 2
Nickname: jido
Registered: Sep, 2003

Persistence and Polymorphic Reads Posted: Sep 14, 2003 7:44 AM
Reply to this message Reply
Advertisement
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.

Animal
|
+---Vertebrate
| |
| +---Mammal
| |
| +---Reptile
| |
| +---Fish
| |
| +---Bird
|
+---InVertebrate
|
+---Insect

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.

Jide Ogundipe


krs1

Posts: 4
Nickname: krs1
Registered: Sep, 2003

Re: Persistence and Polymorphic Reads Posted: Sep 17, 2003 5:38 PM
Reply to this message Reply
Hehehehe, I think Bruce Eckel responded to this one already! ;) His response of keep it simple is a great idea. Its easy to get caught up in framework-syndrome and lose sight of what the hell you're in fact trying to do in the first place, not to mention code bloat for "anticipated" requirements and usage scenarios.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: Persistence and Polymorphic Reads Posted: Sep 22, 2003 9:21 AM
Reply to this message Reply
What, then, is the "simple" solution?

I don't think that the requirements, as defined, are at all "bloated." I think that the problem described is that addressed by O/R mapping tools.

I haven't personally used any that work with C++. If you're thinking of writing your own, though, have a look at the source code for Hibernate.

Main web site:
http://hibernate.bluemars.net

CVS:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/hibernate/

It's written in Java, but I think that it addresses all of your requirements. You could even ask on their mailing list if there is a similar effort for C++. I think someone mentioned on TheServerSide that they were looking into a port to C#.

Flat View: This topic has 2 replies on 1 page
Topic: Compile Time Data Type Checking Previous Topic   Next Topic Topic: C# Text Replacement

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use