The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

ORM Question - Modelling Nested Aggregation?

I'm reading Martin Fowler's Patterns of Enterprise Application Architecture, and I understand how to model normal aggregation (many-to-many relationships), for example:

Database table name :primary_key
A: a_id (PK)
B: b_id (PK)
A_B:a_b_id (PK) a_id (FK), b_id (FK)

becomes in OOP:
Class A, which has a collection of class B's.

But suppose we have nested aggregation (many-to-many-to-many):
A: a_id (PK)
B: b_id (PK)
A_B:a_b_id (PK), a_id (FK), b_id (FK)

C: c_id (PK)
A_B_C: a_b_c_id (PK), a_b_id (FK), c_id (FK)

How do you model this relationship in classes?  From what I understand, you generally don't want to make classes that represent link (association) tables (e.g. A_B or A_B_C above) because they don't really make sense in an OO world , so how do you do it?
Josh Kodroff Send private email
Thursday, June 29, 2006
The first example should be
class A
class B

class ABAssoc
List getA(B forB)
List getB(A forA)

Otherwise you create unncessary (and unhealthy) dependencies between A and B

class C

class ABCAssoc
List getABAssoc(C forC)
List getCAssoc(AB forAB)

Now, A, B, C are strong entities therefore they deserve their generated pks. However the assoc classes are weak entities, therefore I would think long and hard if I'm not better off with a composite key. The reasons is with composite keys you have visibilty back into A, B, C without any extra joins (only a BCNF or 3NF).

select * from ABC, A where ABC.a_id =

Otherwise the query would look like:
select * from ABC, AB, A where
ABC.ab_id = and AB.a_id =
Dino Send private email
Thursday, June 29, 2006

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz