Main Content

Define Sequence Diagrams

A sequence diagram is a behavior diagram that represents the interaction between structural elements of an architecture as a sequence of message exchanges. You can use sequence diagrams to describe how the parts of a static system interact.

You can use sequence diagrams in System Composer™ by accessing the Architecture Views Gallery. Sequence diagrams are integrated with architecture models. For more information on how to create and use sequence diagrams with an architectural model, see Use Sequence Diagrams in the Views Gallery.

In this example, you will learn about the basic terminology and functions of a sequence diagram in two stages.

  • Add lifelines and messages with trigger conditions and constraint conditions to represent interactions.

  • Include fragments and operands with constraint conditions to further specify the behavior of the interaction.

An architectural model and a sequence diagram with a lifeline, gate, operand, message, and fragment.

Add Lifelines and Messages

  1. Create a new sequence diagram by navigating to Views > Architecture Views. The Architecture Views Gallery opens. Select New Sequence Diagram under the new button to create a new sequence diagram.

  2. A new sequence diagram called SequenceDiagram is created in the View Browser and the Sequence Diagram tab becomes active. Select Component > Add Lifeline button to add an element lifeline. A new lifeline with a vertical dashed line is created without a name.

    Creating a new lifeline in a sequence diagram.

  3. Name the lifeline Element 1 and create a second lifeline, Element 2.

    A sequence diagram with two lifelines.

  4. Select the vertical dotted line for the Element 1 lifeline. Click and drag to the Element 2 lifeline. Specify the To and From message ends as In and Out, respectively.

    A sequence diagram with two lifelines and a message between them.

  5. Click on the message to see where to place the message condition. Enter a trigger condition with one of the following trigger events:

    • crossing

    • rising

    • falling

    For example, the message trigger condition could be specified as follows:

    falling(In.elem1 + 5)

    The signal name In.elem1 must be a signal element in a signal interface associated with the port. For more information on interface management, see Define Interfaces.

    The trigger condition must be in this form:

    triggerEvent(signalName (+|-) positiveReal)

    A message trigger condition activates on a zero-crossing event when the value of the port signal is zero, starting from the specified value.

  6. Add a constraint condition using a MATLAB® boolean expression in square brackets. Constraint conditions consist of a boolean expression acting on a signal name.

    [In.elem2 >= 1]

    A sequence diagram with a message condition.

    The constraint condition is an additional check after the trigger condition.

    Note

    Only destination elements are supported for trigger conditions and constraints. In this example, Out is a source element and cannot be included.

Add Fragments and Operands

You can use composite fragments to enable control structures in sequence diagrams. Operands within composite fragments can be further specified with operand conditions composed of MATLAB boolean expressions between signal names.

To access a menu of fragments:

  1. Click and drag to select the message.

    Selecting the message in a sequence diagram.

  2. Pause on the ellipsis (...) that appears to access the action bar.

    Menu to click on in the sequence diagram.

  3. A list of composite fragments appears:

    • Alt Fragment

    • Opt Fragment

    • Loop Fragment

    • Seq Fragment

    • Strict Fragment

    • Par Fragment

    Select Alt Fragment.

    Fragment menu in sequence diagram with alt fragment selected.

  4. The Alt Fragment fragment is added to the sequence diagram message.

    The alt fragment is added to the sequence diagram.

  5. Select the composite fragment to enter an operand condition. Choose a fully qualified signal name and use a constraint condition relation.

    Element 2/In.elem2 > 0

    The constraint determines when the alternative operand is accepted.

    Loop fragment with an operand condition in a sequence diagram.

    The message inside the operand can be executed only if the constraint condition is true.

  6. Highlight the first operand under the Alt Fragment composite fragment and select Fragment > Add Operand > Insert After. A second operand is added.

    A second alt operand is added.

  7. Add a constraint condition relation to the second operand.

    Element 2/In.elem1 ~= 5

    The second alt operand in the sequence diagram has a constraint condition added.

    The second operand in an Alt Fragment fragment represents an elseif condition for which the message will not be executed.

View the Define Sequence Diagrams Example

You can view the final product of the workflow example for this topic.

Open the System Composer model that contains the sequence diagram.

model = systemcomposer.openModel('ArchModelDefine');

Open the Architecture Views Gallery to view the sequence diagram.

openViews(model);

Related Topics