An OOP Design Problem
Posted: Sun Mar 25, 2007 3:10 am
Greetings to all,
I have a question regarding an OOP design problem. Say I have come up with an OO design of classes for instance
Session, User and UserPreferences
A Session object has a User object which has a UserPreferences object.
I have 3 tables in a database a Session, User and UserPreference, and that the classes I have designed maps directly to these tables.
Somehow I got stuck with how am I supposed to fill the data into the classes from the tables respectively?
Do I use an inner join statement and populate the object properties? Or do I fetch progressively accordingly to the order of containment, since the Session object is the first container, I fetch the data for the session first, followed by the User and then the UserPreferences.
Of course, common sense tells me that the inner join might be better off since it's only a single request to the database rather than 3 sql statements one after the other till fill that containment hierarchy of objects.
But seriously, is there a better or more appropriate approach to mapping OO software designs to a RDBMS tables. What I intend to do is to map classes of my application to data rows of the data tables in a database.
Thanks.
I have a question regarding an OOP design problem. Say I have come up with an OO design of classes for instance
Session, User and UserPreferences
A Session object has a User object which has a UserPreferences object.
I have 3 tables in a database a Session, User and UserPreference, and that the classes I have designed maps directly to these tables.
Somehow I got stuck with how am I supposed to fill the data into the classes from the tables respectively?
Do I use an inner join statement and populate the object properties? Or do I fetch progressively accordingly to the order of containment, since the Session object is the first container, I fetch the data for the session first, followed by the User and then the UserPreferences.
Of course, common sense tells me that the inner join might be better off since it's only a single request to the database rather than 3 sql statements one after the other till fill that containment hierarchy of objects.
But seriously, is there a better or more appropriate approach to mapping OO software designs to a RDBMS tables. What I intend to do is to map classes of my application to data rows of the data tables in a database.
Thanks.