As use case diagram can show either an instance (one scenario) of a use case, or it can be generic and incorporate all of the use case's scenarios, and sequence diagrams can be instance or generic sequence diagrams. Generic sequence diagrams often provide opportunities to represent if statements and while loops. Enclose each condition for an "if" statement in square brackets. Do the same for the condition that satisfies a "while" loop, and prefix the left bracket with an asterisk. See Sequence Diagram - Example.
It's possible in sequence diagrams to create an object. When this occurs, you represent a created object in the usual way - as a named rectangle.
The
difference is that you don't position it at the top of the sequence diagram as
you do with the other objects. Instead, you position it along the vertical
dimension so that its location corresponds to the time when it's created. The
message that creates the object is labeled Create().
Sometimes an object has an operation that invokes itself. This is called recursion.
Suppose one of the
objects in your system is a calculator, and suppose one of its operations
computes interest. In order to compute compound interest for a timeframe that
encompasses several compounding periods, the object's interest-computation
operation has to invoke itself a number of times. Sequence diagram for this is
following:
|
Representing recursion in a sequence diagram |