Activity Diagram

Activity diagrams (UML) are often confused with Flowchart diagrams (not UML nor specific to programming) as they are similar πŸ—ΊοΈ.

It represents every state πŸ“ of the program and how we transit ✈️ from one state to another.

For instance, in a game menu, we may have some states such as:

  • MainMenu
  • Load Game
  • Select Character
  • QuitGame

The transitions are the options we select to navigate between them.

Activity Diagram Example


States

A state is essentially one of the program's states. There are 3 kinds:

  • ⚽ Initial States
  • πŸ§‘ Intermediary States
  • πŸ₯… Final States

When a program is starting, we are moving from one of the initial states to one of its linked intermediary states. We are moving between intermediary states until we reach a final state.

Basic Diagram

The initial state is represented as a solid black circle filled with black. The final state is represented as an empty black circle with a solid black circle filled with black inside.

Each state may contain some methods:

  • entry/action: where action is executed when entering this state
  • exit/action where action is executed when exiting this state

Entry-Exit for States


Transitions

Transitions are the arrows linking one state with another. On each, you may add one of these:

  • A trigger/event that we are waiting for

Transitions Trigger

  • An action that we are triggering and waiting for its end

Transitions Action

  • A condition such as [money > 10€]

Transitions Condition

Branching

Both syntaxes are used to represent branching. You can have as many branches and conditions as you want.

UML If Syntax 1 UML If Syntax 2

The most fitting condition is the one that will be used. You may add a note to ensure there is no doubt about it. A better approach is to only use True and False and chain them.


Synchronization bar

The synchronization bar is used when we want to do parallelism. The first indicates that the states below are executed in parallel (fork) and the second indicates that we wait for all forks to terminate (join).

Fork