In previous lesson we learned state diagrams, which focus on the states of na object. But it's necessary to have communication between objects. The UML sequence diagram goes the next step and shows how objects communicate with one another over time. In this expanded field of view, you'll include an important dimension: time. The key idea here is that interactions among objects take place in a specified sequence, and the sequence takes time to go from beginning to end.
The
sequence diagram consists of objects represented in the usual
way - as named rectangles (with the name underlined), messages
represented as solid-line arroes, and time represented as a
vertical progression.
Let's take a close look at this parts of sequence diagrams.
Objects
The objects are laid out near the top of the diagram from left to right. They're arranged in any order that simplifies the diagram. Extending downforward from each object is a dashed line called the object's lifeline. Along the lifeline is narrow rectangle called an activation. The activation represents an execution of an operation the object carries out. The length of the rectangle signifies the activation's duration. This is shown on next picture.
Representing an object in a sequence diagram |
Messages
A message that goes from one object to another goes from one object's lifeline to the other object's lifeline. An object can send a message to itself-that is, from its lifeline back to its own lifeline. This is called recursion. See recursion example.
Following table lists all of possible messages existing in the UML sequence diagrams, with their graphical representations:
simple | This is a transfer of control from one object to another. | |
synchronous | If an object sends a synchronous message, it waits for an answer to that message before it proceeds with its business. | |
asynchronous | If an object sends an asynchronous message, it doesn't wait for an answer before it proceeds. |
Time
The diagram represents time in the vertical direction. Time starts at the top and progresses toward the bottom. A message that's closer to the top occurs earlier in time than a message that's closer to the bottom.
The essential symbol set of the sequence diagram, with the symbols working together. |
The
actor-symbol initiates the sequence, but the stick figure isn't part of the sequence
diagram symbol set.
In
a sequence diagram, the objects are laid out from left to right across the top. Each
object' lifeline is a dashed line extending downward from the object. A solid line with an
arrowhead connects one lifeline to another, and represents a message from one object to
another. Time starts at the top an proceeds downward. Although an actor typically
initiates the sequence, the actor symbol isn't part of the sequence diagram's symbol set.