UML class model how to model many to many relationship

Peter picture Peter · Aug 20, 2009 · Viewed 41.7k times · Source

I have read several tutorials on what a UML model should contain and what not. As a developer I always think in terms of a relational data model where you could never have a many to many relationship between tables. Now with a UML class model, I've read that if they don't provide added value, you could just skip the linktables.

However I've also read a tutorial where examples where given using data inside tables and was strongly suggesting to picture each class as a simple table while modeling your class model.

I am confused, what is it now?!

Answer

S.Lott picture S.Lott · Aug 20, 2009

The "relational link table" is an implementation technique for a Many-to-Many relationship.

The relationship exists irrespective of how it's implemented.

In an object model, you have many choices for how to implement many-to-many, which may (or may not) involve an additional persistent table. It could be done lots of different ways.

The point of UML is to be able to describe the essential features of what the model really is.

You can also describe the implementation. They're separate diagrams with separate purposes. You can easily show the relational implementation with the link table. You can also show the essential model without the link table.

Here's the essential relationship

Essential

Here's the implementation of the relationship

Implemntation

Both are valid UML. The real question is "what do you need to show other people?" Essential truth or one particular implementation?