CHAPTER 6 ■ OBJECTS AND DESIGN
message originator). Each message is labeled using the relevant method call. You can be quite flexible
with your labeling, though there is some syntax. Square brackets represent a condition. So
[okToPrint]
write()
means that the write() invocation should only be made if the correct condition is met. An asterisk is
used to indicate a repetition, optionally with further clarification in square brackets:
*[for each ShopProduct]
write()
Figure 6–20. The complete sequence diagram
You can interpret Figure 6–20 from top to bottom. First, a Report object acquires a list of
ShopProduct objects from a ProductStore object. It passes these to a ShopProductWriter object, which
stores references to them (though we can only infer this from the diagram). The ShopProductWriter
object calls ShopProduct::getSummaryLine() for every ShopProduct object it references, adding the result
to its output.
As you can see, sequence diagrams can model processes, freezing slices of dynamic interaction and
presenting them with surprising clarity.