many-to-manyumlanalysisclass-diagramjunction-table

UML class model how to model many to many relationship


I have read several tutorials on what a UML model should contain and what it shouldn't. 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 link tables.

However, I've also read a tutorial where examples were 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?


Solution

  • 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?