Re: Class Structure Question



On Jun 4, 5:39 pm, dweesie <dwee...@xxxxxxxxxxxx> wrote:
This is an opinion question, with background first.

Let's say I have a table
<u>aaaa</u>
a_id (pk)
a_name
a_descrip

and another table
<u>bbbb</u>
b_id (pk)
b_name
b_descrip

and another table to create a many to many
<u>aabb</u>
a_id (fk)
b_id (fk)

If I create a class for aaaa, obviously I would include fields for id,
name, and description. My data access object would have sql to
populate those fields for certain. Now here's my opinion question.
Does your aaaa class also include a list of foreign keys to bbbb? Do
you create an aabb class? Should you include any data from bbbb in
the aaaa class (this one seems an obvious no)? When is the
appropriate time to get related data? I don't have a particular
scenario. I'm just looking for opinions.

your Aaa class should have a java.util.Collection of associatedBbbs,
which should include a reference to every associated Bbb. The same, of
course, in the Bbbs the other way around. The data accessor should
read the aabb table and populate everything both ways (or, for
efficiency, take as a parameter whether to populate one way, both or
not at all). I think an AaaBbb class for the associations would be bad
design in most cases.

Tzvika

.