8/26/2021»»Thursday

Plantuml Sequence

8/26/2021
    99 - Comments

This macro can be used to add various UML, ditaa or JCCKit diagrams to a confluence wiki page. Similar to the Confluence wiki markup, the diagram is defined as a simple text using a special syntax defined by the PlantUML Project.You don't need any drawing editor to draw such diagrams! PlantUML’s terse syntax is generally formatted as a keyword identifier followed by the name of the subject. For properties, a colon goes between the property name and its type. For methods, use parentheses immediately after the method name.

  1. Plantuml Sequence Diagram Note
  2. Plantuml Sequence Diagram Parallel
  3. Plantuml Parallel Sequence Diagram
  4. Plantuml Sequence Diagram
  5. Plantuml Sequence Diagram Conditional
.NET ToolsHow-To'sPluginsRider

UML, or Unified Modeling Language, is, as the name implies, a modeling language that allows you to visualize systems. In this post, we’ll look at how PlantUML enables you to create various kinds of diagrams so that you can properly document your software. We’ll create two of the most popular UML diagram types: Class and Use Case diagrams, to demonstrate what you can do with the PlantUML plugin in Rider.

UML Overview

UML is a language. But it isn’t a programming language in the sense C#, Java, or Python are. UML is a visual way to convey information about software or systems, through diagrams.PlantUML is a UML-based component that enables you to draw diagrams using a concise syntax. UML diagrams come in many flavors, including the following popular types of diagrams:

  • Class: Diagrams all of the classes in a program, and how they are related.
  • Component: Shows the various components of a system and how they interact.
  • Use case: Visually demonstrates varying scenarios in how users and other software interacts within a system boundary.
  • Activity: Graphic representation of workflows of a system.
  • Sequence: Outlines the steps that are necessary for a system or part of a system to function.
  • State-machine: Describe the behavior of objects that act differently according to the state they are in at the moment.

In addition, PlantUML supports Object, Gantt, MindMap, Wireframe, and Work Breakdown Structure diagrams. Most teams don’t create every type of diagram for a system. Instead, they tend to choose which UML diagram types are the most meaningful that help the team and other stakeholders better understand the software. For example, a team that works on UIs might find Use Case diagrams helpful, while the back-end team might find Sequence and State-machine diagrams work better for their software.

Create UML diagrams with PlantUML

Use the PlantUML plugin in Rider to create UML diagrams that can be integrated into your codebase. Start by adding a .puml file. Each new file that PlantUML creates contains example PUML, which is PlantUML’s own syntax for creating UML diagrams. Because PUML syntax is clean, compact, and efficient, folks can use it not just for visual diagrams but also as a basis for code generation or documentation.

Notice the PUML syntax and the corresponding visualization in the PlantUML tool window to the right of the editor window. All PlantUML files begin with the @startuml marker and end with the @enduml marker. In between these markers is basic syntax that generates the diagrams, though diagrams can be as complex as is necessary

PlantUML’s terse syntax is generally formatted as a keyword identifier followed by the name of the subject. For properties, a colon goes between the property name and its type. For methods, use parentheses immediately after the method name. As you write these tokens, PlantUML automatically and immediately creates the UML diagrams, and updates the visual map that is shown in the PlantUML tool window.

A few PlantUML syntax basics:

interface interface-name
class class-name
abstract class class-name
property: data-type
method-name()

Colors and other visual indicators are customizable through PlantUML syntax.

Use the PlantUML toolwindow to manage diagrams, for example, refreshing or zooming into a diagram. You may want to save them as a separate file, perhaps to include in documentation. PlantUML supports .png,.svg, .utxt, .atxt, and .eps formats when saving.

Class diagrams

Class diagrams present the business objects from a system, along with an outline of their data and behaviors and how they relate to each other. Diagrams give developers a view as to the overall structure of a program. Class diagrams are used for many purposes, from generating data models in code to serving as documentation.

For example, if a class diagram is needed for a university, the following syntax can be used to create the following diagram. Notice the PlantUML syntax contains tokens for everything that UML requires, such as access modifiers (# for protected, + for public) and data types after a colon. To create an inherited model, use the Base < -- Derived syntax. While this example shows only a few features of an object model, PlantUML supports other access modifiers and markers for composition and aggregation as well.


Classes in PlantUML diagrams can represent classes in C#, Java, or any OO language. Mophie powerstation mini. In this case, PlantUML’s syntax is almost the same as C#. Use the class keyword, curly braces, then list the members and types (but no code!). This familiarity should ease the burden of creating diagrams that match objects in your model.

Use cases

Use case diagrams demonstrate the interaction between users (actors) and software, and between software components. They are an excellent way to get a snapshot of which parts of a complex system must integrate together, and how components connect to each other, as well as some system flow.

Below is a sample of PlantUML use case syntax and an accompanying visual diagram:


Notice some of the syntax: rectangle is used to define the system boundary. Actors are defined by the actor keyword, and the relationship between actors and objects (or objects to objects) are defined with --->. The use cases themselves are enclosed in parentheses. PlantUML really does have precise syntax, which can help you create diagrams faster with better efficiency.

Summary

Most companies, especially large organizations with complex software, need to model, map, and manage their software with industry-standard UML diagrams. PlantUML supports the most popular kinds of UML diagrams and should suit most needs.

If you’re using Rider, diagramming your systems is built into the product as a plugin, giving you an advantage to complete projects faster and more efficiently. So download Rider today, and show us your diagrams!

A UML Sequence diagram shows how messages go back and forth between objects over time. It is an interaction diagram.

The basic syntax for a line in a sequence diagram shows that one participant is sending a message to another participant:

More formally: <participant1><directionalarrow><participant2>:<message>

Sequence diagram showing interaction between Alice and Bob:

Here is the source for the diagram:

Keywords¶

Sequence

Be sure to also read about the keywords and options that can be applied to all diagrams:Global keywords and options

Participants¶

Todo

words about what participants are in general. types…

Usage:

participant'<displaylabel>'

[as<somealias>]

[#<colornamehexcode>]

[<<[(<letter>,<color>)][stereotypename]>>]

[order<number>]

Participants are the message senders. Use the participant keyword to give a name to a message sender and optionally give it an alias and format it.

If the displayed label for a participant has spaces or special characters, put quotes around it. (Ex: 'RequestHandler')

You don’t have to use the participant keyword because PlantUML will automatically display a sender whenever it encounters one in the source.But using the keyword gives you the ability to set the following options:

You can use a participant line anywhere in your source (at any time).This is one way you can control the order of the participant boxes across the top.

Options:
as <some alias>:

provide an alias for the participant. This is useful if the displayed name is long; you can just use the shorter alias in the rest of the source.

color #<colorName hexCode>:

set the color of the image displayed. Use a color name or hex code.

Ex: participantAlice#lightGreen

<< [(<letter>, <color name>)] [<stereotype text>] >>:

(stereotype box) …

Ex: participant'RequestHandler'<<(S,#lightBlue)server>>

order <number>:

set the specific order for the participant. Otherwise PlantUML just orders the participants as it encounters them.

order must come last else you’ll get a syntax error!

Ex: participant'RequestHandler'order3

Example:

You can show a message coming from or going to a participant not in the scope of the current diagram by using ] or [

  • ] shows a message going to outside the scope of the diagram (to a participant not in the diagram)
  • [ shows a message coming from outside the scope of the diagram (from a participant not in the diagram)
Skinparams:

Participant

ParticipantBorderThickness

actor

actor is a stereotype (synonym) for participant that displays a person stick figure instead of the standard box. All of the same options as participant can be used.

Skinparams:

ActorBorderThickness

Actor { } – note that the last Actor skinparams read will be the ones that are applied!

boundary

boundary is a stereotype (synonym) for participant that displays a boundary image instead of the standard box. All of the same options as participant can be used.

entity

entity is a stereotype (synonym) for participant that displays an entity image instead of the standard box. All of the same options as participant can be used.

control

control is a stereotype (synonym) for participant that displays a control image instead of the standard box. All of the same options as participant can be used.

database

database is asynonym for participant that displays a database image instead of the standard box. All of the same options as participant can be used.

create

create puts the first occurrence of the diagram for the participant within the diagram where this word appears instead of at the top of the page.Helps to show that an object is actually created at that point in time.

Usage:create <name> order <order number>
  • cannot use “as”

    In the example above, create'AuthSystem' is used to show exactly when the wrappedRequest is created

Arrows (Graphic Paths)¶

Arrows are used to show messages sent to and from participant along a graphic path.

Skinparams:

Special note about arrows and skin params: the last one is the one used. ( an include and reference to .?)

ArrowThickness

Ex: skinparamSequenceArrowThickness4

Ex: skinparamSequence{ArrowThickness4}

MessageAlignment

MessageTextAlignment

Arrow Heads¶

Solid arrow heads represent synchronous messages. Open (not filled in) arrow heads represent asynchronous messages. (See the UML 2.5 Specification, section 17.4.4.1 Message Notation)

>> creates an unfilled arrow pointing to the right (This is an asynchronous message.)

<< creates an unfilled arrow pointing to the left (This is an asynchronous message.)

> creates a filled (solid) arrow head pointing to the right (This is a synchronous message.)

< creates a filled (solid) arrow head pointing to the left (This is a synchronous message.)

creates the top half (only) of an unfilled arrow pointing to the right

// creates the bottom half (only) of an unfilled arrow pointing to the right

creates the top half (only) of a filled arrow pointing to the right

/ creates the bottom half (only) of a filled arrow pointing to the right

? means the arrow line is short; it is only as long as the label for it.

If the ? is at the end, the arrow line is connected to the start (origin) and stops when the label for it stops.

If the ? is at the end, then the arrow is connected to the end (target), and the arrow line is only as long as the arrow label.

o puts a final “o” at arrow head, denoting a lost message

x puts an *X* at the end, denoting a destruction message.

You can create a bidirectional arrow by putting arrow heads at both ends of a line. Ex: <->

Arrow Lines¶

Solid lines show messages sent. Dashed lines represent reply messages.

An object creation Message has a dashed line with an open arrow head.

- creates a solid line

-- (two dashes instead of just one) creates dotted line

Note

If you use dots .. for an arrow line, PlantUML will think you are working with a Use Case diagram instead of a Sequence diagramand will change how it draws (renders) it.

You can make dashedarrow lines as long as you want, but they will be drawn only as long as needed andcalculated by Graphviz.

Ex: You can do this:

And it will be rendered/drawn like this:

Arrow Color¶

You can change the color of an arrow by putting the color within square brackets just before the ending arrow-head characters:

Ex: -[#magenta]>> will create a magenta colored unfilled arrow with a solid line

Ex: --[#939393]> will create a gray colored filled arrow with a dashed line

Plantuml Sequence Diagram Note

Autonumber Graphic Paths¶

Usage:

autonumber[startresume][increment][format]

  • automatically number each arrow in the sequence
  • can format the numbering: “<b>(<u>##</u>)”
    • must be in double quotes
    • accepts simple printf type formatting (## 0 etc)

Todo

autonumber

resume
autonumber stop

Lifelines (ExecutionSpecification)¶

The activate and deactivate keywords are used to denote participant activation and deactivation on its lifeline.The UML 2.5 specification refers to this as an ExecutionSpecification: exactly what messages are called, and in what order, are specified in this particular section of the diagram.

You can also explictly destroy the lifeline of a participant, showing exactly when something is destroyed.

Skinparams:

LifeLineBackgroundColor

LifeLineBorderColor

LifeLineBorderThickness

Usage:activate<participant>[color]
deactivate
Usage:deactivate<participant>
Usage:destroy<participant>
Plantuml

Frames Around Fragments¶

Frames are rectangular boxes around a fragment (or sub-clause) of a sequence. It is a box around certain participants and messages.There is a name in the upper-left corner of the frame and, in the case of a group box, optionally a label across the top of the frame.

  • All frame keywords must have a correspondingend to signal where the frame ends
  • You can nest frames
  • You cannot use a note within a frame
  • See section 17.6 in the UML 2.5 Specification
  • PlantUML does not implement all InteractionOperator kinds, but you can use the group box to put in the name of any InteractionOperator you want.
Skinparam:

Even though these skinparams start with Group they apply to all frames.

  • The GroupHeaderFont formats the text that appears in the pentagon in the upper-left-hand corner of the frame. Here are the specific skinparam options:

    GroupHeaderFontColor

    GroupHeaderFontName

    GroupHeaderFontSize

    GroupHeaderFontStyle

  • GroupBodyBackgroundColor formats that background color of the frame. Here are the specific skinparam options:

    GroupBorder formats the border of the frame.

    GroupBorderColor

    GroupBorderThickness

  • GroupFont formats the text at the top of the frame. Here are the specific skinparam options:

    GroupFontColor

    GroupFontName

    GroupFontSize

    GroupFontStyle

Usage:

alt'<text>'

<..whatevergoeswithinthebox..>

end

InteractionOperator alt is used to show one or more alternative sequences that can happen. A dashed lineis used between the possible alternative sequences.

alt is the frame name in the pentagon in the upper left hand corner.

text is displayed in square brackets ([]) at the top of the frame; it describes or labels frame as a whole.

else
Usage:

else'<text>'

<..whatevergoeswithinthebox..>

end

In the UML specification, else is the default sequence in a list of alternative sequences.The else InteractionOperator is used to show the sequence that will be used if the none of conditions forthe alt alternatives can be met. else is the frame name in the pentagon in the upper left hand corner.

But in PlantUML_ this is how you label different alternatives. You can use the groupkeyword to specifically display the word “else” and use it per the UML Specification.

text is displayed in square brackets ([]) at the top of the frame; it describes or labels this alternative.

Example:
opt
Usage:

opt'<text>'

<..whatevergoeswithinthebox..>

end

An optional sequence. It either happens or not.

opt is the frame name in the pentagon in the upper left hand corner.

text is displayed in square brackets ([]) at the top of the frame; it describes or labels frame as a whole.

Usage:

loop'<text>'

<..whatevergoeswithinthebox..>

end

Shows a sequence that loops.

loop is the frame name in the pentagon in the upper left hand corner.

text is displayed in square brackets ([]) at the top of the frame; it describes or labels frame as a whole.

par
Usage:

par'<text>'

<..whatevergoeswithinthebox..>

end

Shows a parallel sequence.

par is the frame name in the pentagon in the upper left hand corner.

text is displayed in square brackets ([]) at the top of the frame; it describes or labels frame as a whole.

Usage:

break<text>

<..whatevergoeswithinthebox..>

end

shows that a sequence breaks. It stops (does not perform) any of the remaining sequence does this instead.

break is the frame name in the pentagon in the upper left hand corner.

text is displayed in square brackets ([]) at the top of the frame; it describes or labels frame as a whole.

Plantuml
critical
Usage:

critical'<text>'

<..whatevergoeswithinthebox..>

end

A fragment of a sequence that cannot be “interleaved” by other fragments (e.g. parallel fragments, etc.).

critical is the frame name in the pentagon in the upper left hand corner.

text is displayed in square brackets ([]) at the top of the frame; it describes or labels frame as a whole.

Usage:

group'<framename>'

<..whatevergoeswithinthebox..>

end

allows you to fully specify the frame name.

frame name is the frame name in the pentagon in the upper left hand corner.

Note that you cannot add text after the frame name.

Reference Frame (InteractionUse)¶

Usage:

ref'<framename>'

A reference to some other interaction or diagram.ref is the frame name in the pentagon in the upper left hand corner.

Skinparam:ReferenceAlignmentReferenceBackgroundColorReferenceBorderColorReferenceBorderThicknessReferenceFontColorReferenceFontNameReferenceFontSizeReferenceFontStyleReferenceHeaderBackgroundColor

Todo

example for reference frame

Usage:

..[<text>..]

Indicates a delay in the diagram. You can optionally add text to describe the delay.

Plantuml Sequence Diagram Parallel

Skinparam:DelayFontColorDelayFontNameDelayFontSizeDelayFontStyle

Todo

Example for delay

Spacing¶

  • or <number of pixels>

Dividers¶

Skinparam:DividerBackgroundColorDividerBorderColorDividerBorderThicknessDividerFontColorDividerFontNameDividerFontSizeDividerFontStyle

Notes¶

Notes for Participants¶

  • for participants:
    • put this under section about participants?

Notes for Arrows¶

Plantuml Parallel Sequence Diagram

  • for arrows (graphic paths) (messages)
    • put this info under the section about graphic paths?

Todo

newpage - is this common? or only on sequence diagrams?

Plantuml Sequence Diagram

A longer sequence of events with some skinparam styles used:

Plantuml Sequence Diagram Conditional

Skinparams specific to Sequence Diagrams¶