tags:

views:

75

answers:

3

For a program with an OO front-end and a SQL back-end, can one have each parent class map to its own table and each child class map to it's own table, then use joins in queries to allow returning all the child class's attributes? If so, is it advisable?

A: 

Yes it is possible. Object-Relational Mapping frameworks suchas NHibernate and Hibernate take care of these things for you.

Daniel A. White
+1  A: 

Sure, you can do that with an ORM tool like Hibernate or Entity Framework. As to whether it's advisable, that's a religious question -- I try not to answer those. :)

JP Alioto
+1  A: 

It is very possible and reasonably widespread. It also works well when you have minimal sub-classing, and the business logic maps easily to the objects being used. However, with only a little extensability in the mapping layer, you can easily create objects that are combinations of several tables, perhaps even doing sub-classes. (I've written such layers and take care to make such hooks possible.)

It is advisable to always use a data mapping layer because you do not want excessive SQL littering your code. OTOH, if your class structure is more heirarchical rather than relational, you might look at an OO database (I hear PostGreSQL can do that) and a suitable mapping layer.

staticsan
Thanks to all but this answer seems like the most complete.
ChrisC