You are on page 1of 16

TCSS 360, Spring 2005 Lecture Notes

UML Sequence Diagrams
Relevant Reading: UML Distilled, Third Edition, Chapter 4 M. Fowler

along the Y axis.UML sequence diagrams  sequence diagram: an "interaction diagram" that models a single scenario executing in the system  perhaps 2nd most used UML diagram (behind class diagram)  A sequence diagram is an interaction diagram that emphasizes the time ordering of messages. relation of UML diagrams to other exercises:     CRC cards -> class diagram use cases -> sequence diagrams 2 . a sequence diagram is a table that shows objects arranged along the X axis and messages. Graphically. ordered in increasing time. It shows a set of objects and the messages sent and received by those objects.

Key parts of a sequence diag.  participant: an object or entity that acts in the sequence diagram  sequence diagram starts with an unattached "found message" arrow  message: communication between participant objects the axes in a sequence diagram:  horizontal: which object/participant is acting  vertical: time (down -> forward in time)  3 .

The line is called the object lifeline. and it represents the existence of an object over a period of time.Sequence Diagram an Order Line An object in a sequence diagram is rendered as a box with a dashed line descending from it. 4 .

Sequence diag. from use case 5 .

Collaboration Diagram Sequence Diagram Both a collaboration diagram and a sequence diagram derive from the same information in the UML’s metamodel. 6 . so you can take a diagram in one form and convert it into the other. They are semantically equivalent.

Representing objects  squares with object type. optionally preceded by object name and colon   write object's name if it clarifies the diagram object's "life line" represented by dashed vert. line 7 .

Messages between objects  message (method call) indicated by horizontal arrow to other object  write message name and arguments above arrow   dashed arrow back indicates return different arrowheads for normal / concurrent (asynchronous) methods 8 .

drawn when object's method is on the stack   either that object is running its code.Indicating method calls  activation: thick box over object's life line. or it is on the stack waiting for another object's method to finish nest to indicate recursion Activation Nesting 9 .

indicate it with either:    an unfinished arrow and comment a "ref" frame that names the other diagram when would this occur in our system? Customer Info ref Verify customer credit Approved? 10 .linking sequence diagrams  if one sequence diagram is too large or refers to another diagram.

Example sequence diagram sd Example StoreFront Cart Inventory loop AddItem ReserveItem Checkout ProcessOrder ConfirmOrder PlaceItemInOrder 11 .

(De)centralized system control  What can you say about the control flow of each of the following systems?   centralized? distributed? 12 .

Flawed sequence diagram 1  What's wrong with this sequence diagram? (Look at the UML syntax and the viability of the scenario.) 13 .

Flawed sequence diagram 2  What's wrong with this sequence diagram? 14 .

Flawed sequence diagram 3  What's wrong with this sequence diagram? :Computer :PrintServer :Printer :Queue print(file) [if printer free] print(file) [else] enqueue(file) 15 .

So why not just code up that algorithm rather than drawing it as a sequence diagram?      a good sequence diagram is still a bit above the level of the real code (not EVERY line of code is drawn on diagram) sequence diagrams are language-agnostic (can be implemented in many different languages non-coders can do sequence diagrams easier to do sequence diagrams as a team can see many objects/classes at a time on same page (visual bandwidth) 16 .Why not just code it?  Sequence diagrams can be somewhat close to the code level.

.4  . :965.3.9.1:8501.::8501.4 ..9.

1:8501.::8501.. :965.07 15739071700(5739 10 080(036:0:0 10 !73907 ":0:0 5739 10  .9.4 .3..9.4 425:907 !739$07.

0617.9.33.4 :8501. 9.5.036:.9.:..56.%356061:19.5..5651..93.. .4::.:.336...:850 1. .519.661:8501..06133 &656.6 ..369.3061 56.49.9.:./.9.5/:64. &8501.

: 565.5195.56:.154..0 0.5/ 47345.5.3.

616:8501.9.511....5:4.56/0.47.:03...   .:9.9.:.465:.4 0.4: .:::. :.3/.4:.0619:0.516:8501.