Aggregation poses a problem when interpreting some of the related associations. The composition context helps to rectify this problem.
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's add some additional associations to show where this notation breaks down.
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
Step through the creation of the book composition context to see how the parts fit together.
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.