Tuesday, June 2, 2009

UML Sequence Diagram: Interaction Fragment (Alt, Opt, Par, Loop, Region)

A common issue with sequence diagrams is how to show conditions and iterations. Indeed, the activity diagram is more appropriate to model control logic that involves conditions, loop etc, but in practice, most developers prefer to stick with the sequence diagram to show how objects interact together with the control logic involved.  

Using Notations

A simple way of presenting conditions and loops is using simple notes. The sequence bellow shows CarsManager that iterate though collection of Cars and execute a wash on each Car, which in turn delegate to the appropriate strategy according to the requested technique.

image

Using Interaction Frames (Combined Fragment)

Another way of presenting control logic is using fragments (a.k.a interaction frames) together with Interaction Operators.

With fragments we can delimit set of calls to show that they 1) execute only if a given condition is true 2) execute in a loop 3) run in parallel 4) reside within a critical section 5)etc. The latter calls can be partitioned to groups (combined fragment) to show according to which condition each group will execute.

Interaction Operators (shown below) are used to characterize the fragment. For instance, in order to define that a call will execute only if a certain condition is true – we delimit the call with a fragment and use the operator ‘Opt’ to specify the condition. 

The following table provides guidance on the most useful operators, and their corresponding descriptions.

alt

Divides fragment into groups and defines condition for each group -  only the one whose condition is true will execute .

opt

Defines condition to a single call - the call will execute only if the supplied condition is true . Equivalent to an alt with only one trace.

par

Defines that the calls within the fragment run in parallel.

loop

Defines that the calls within the fragment run in a loop.

region

Defines that the calls within the fragment reside in a critical section, i.e. the fragment can have only one thread executing it at once.

 

 image

 

Links

http://resource.visual-paradigm.com/uml_diagrams/sequence_diagram/sequence_diagram_notation.html

4 comments:

  1. Thanks a lot. Now I know how to use alt)

    ReplyDelete
  2. Dear Aviad Ezra

    your this topic also helped me.
    what tool you you normally use for UML?

    Rizwan Ishtiaq

    ReplyDelete
  3. You just saved my ass man....Thanks a mil

    ReplyDelete