10.2. Interaction ParticipantsYou show participants in an interaction using a rectangle called a lifeline. The term lifeline illustrates UML's bias toward representing interaction diagrams using the sequence diagram notation. When shown in sequence diagrams, participants have a dashed line dropping down from a rectangle that shows how long the object is actually in existence. When used in other interaction diagram notations, such as communication diagrams, a lifeline is simply a rectangle. You show the name of the participant in the rectangle using the following notation: object_name [ selector ] : class_name ref decomposition where:
UML defines a reserved participant name, self, that indicates the participant is the classifier that owns this interaction diagram. Figure 10-2 shows a trivial interaction diagram with two participants and a message between them. Figure 10-2. A trivial sequence diagram with two participantsYou can show the destruction of a participant during an interaction using a stop symbol. Typically this is preceded by a «destroy» message to the object, though that isn't strictly necessary. Place an X at the bottom of the lifeline where the object ceases to exist. Figure 10-3 shows destroying a helper class after it has finished its work. Figure 10-3. The destruction of a participantTo help make your sequence diagram accurately capture the behavior you are trying to model, you can introduce local variables. Local variables can hold return values, loop information, or just data you need for later processing. You show the values of local attributes relevant to the interaction using the same attribute syntax used inside of classifiers (see Chapter 2). Place their name and values in the upper left of the diagram, or in a note attached to the diagram. Figure 10-4 shows a more detailed version of the HashMap interaction using local variables. Figure 10-4. A more complete HashMap interaction using local variablesIn addition to local variables, sequence diagrams can access data in the participants. See "Messages" for examples. |