4.3.1.  Relationships Summary

[ fromfile: relationships.xml id: relationships-summary ]

As we have seen, a relationship can be an aggregate (purely for navigation) or a composite. A composite relationship is a stronger one, which also describes a parent-child or container-contained relationship. In addition, each relationship has the following properties:

  1. cardinality, which can be one-to-one, one-to-many, or many-to-many. Often, a number (1, 1..5, *) next to the end of the line segment will specify this.

  2. navigibility, which can be unidirectional, or bidirectional. Unidirectional relationships may have arrows instead of diamonds on the line segments between classes.

Figure 4.3 shows an example using containment as well as unidirectional relationships.

Figure 4.3.  Books and Pages

Books and Pages

In this diagram, a Book is a container of Pages, but additionally, the pages have their own navigation relationships. Perhaps a reader (or browser) would benefit from direct navigation links to neighboring pages, as well as the table of contents. Each of these is a unidirectional relationship, so we could show three self-pointing arrows and the diagram would not be incorrect.

For the m_pages relationship, there is no reverse relationship shown, so this could describe a unidirectional or a bidirectional containment relationship. If there is need for the Page to navigate to its containing Book object, we should make the directionality more clear in the diagram. We could do this by labeling the other end of the relationship, and/or by adding an m_Book attribute to the Page class.