Home

 

Creating lifelines

A lifeline represents the existence of an object involved in an interaction over a period of time. A lifeline is depicted as a rectangle representing the object involved in the interaction which contains the object's name, type, and stereotype with a vertical dashed line beneath indicating the progress of time.

Figure | -35 shows several examples of possible lifelines for objects of a class called Customer. It is important to note that the terminology used with sequence diagrams is different in UML 2.0 and later when compared with earlier versions of UML. Also, text in a lifeline object box does not have to be underlined although it can be rendered that way if required.

The first lifeline represents an instance of the Customer Java class and the instance is named customer.

The second lifeline represents an anonymous instance of the Customer Java class.

The last lifeline represents an object named customer whose type is not shown.

Figure 7-35 Different representations of lifelines on a sequence diagram

To add a lifeline from an existing Java class or interface to a sequence diagram, select the desired element in the Enterprise Explorer view and drag it on an empty place in the diagram. This creates a new lifeline and places it at the top the diagram aligned horizontally with the other lifelines. If you drag a different class over the top of an existing lifeline on the sequence diagram then the class of the lifeline is changed to the new class.

You can also use the tool palette to create a new lifeline. Select Lifeline in the palette and drop it on an empty space inside the diagram. Note that this creates a lifeline representing an object whose type is not specified but with a default name. After a lifeline is created, you can change the name and type of the object it represents.

To change the name, select the lifeline's shape and enter the new name. To change the type and a class or interface is available in the Enterprise Explorer, select the desired class or interface in the Enterprise Explorer and drag it on the lifeline's shape. You can also use the Properties view to review or change any property of a given lifeline.

By default, a lifeline is shown as a rectangle containing the lifeline name, type, and stereotype. If you right-click a lifeline, the Filters submenu provides several options to change the lifeline's appearance.

ibm.com/redbooks