Logical View  «Prev  Next»
Lesson 9 Composition context
Objective Define composition context and its notation.

UML Composition Context

A better interpretation

Aggregation poses a problem when interpreting some of the related associations. The composition context helps to assist with the problem of interpreting some of the related associations.
Take a look at the Book class diagram below. When we first showed this example to you, we used aggregation. Realistically, it would be better modeled as composition, because the chapters and other parts cannot exist apart from the book. Now let us add some additional associations to show where this notation breaks down.

Book example
Book example
Looking at the Book class diagram, can you determine whether or not a footnote can refer to chapters in the same book or only chapters in other books, or if footnotes may refer to the book in which they reside or only to other books?
The context notation provides a very precise specification that handles these limitations of the current diagram. Start with a large rectangle. The name of the composite class becomes the name of the context. Inside the context, place the component class or classes. The nesting continues for all levels of the composition. Place the multiplicity of the parts in the top-right corner of the context box. The name of the part may be just the class name or it may include the role that the part plays in the composition, using the notation role:classname. Step through the creation of the book composition context to see how the parts fit together.

1) book-composition 1 2) book-composition 2 3) book-composition 3 4) book-composition 4 5) book-composition 5 6) book-composition 6
  1. Start with the Book context. Draw the box and place the name at the top.
  2. Place the Chapter context inside of the Book context to show containment. Name the new component context and place the multiplicity in the top right corner.
  3. Place the Footnote context inside the Chapter context to show containment.
  4. A footnote may refer to another Chapter in the same book. Draw the association line from the edge of the Footnote out of the Chapter context and back to the outside edge
  5. Footnotes can also refer to Chapters in other Books. Draw the association line from the outside edge of the Footnote, out of the Chapter and the Book context,
  6. A Footnote can refer to the Book in which it resides. Draw the association line from the Footnote to inside edge of the Book context.

Book Composition Context
The context diagram is a general-purpose tool for presenting your models. Composition is only one possible use. Use the context diagram for any presentation where you want to limit the scope of the elements under review. In the next lesson, you will learn the notation for specifying inheritance.