メインコンテンツまでスキップ

Sequence

sequenceについて学習します

sequenceはエンティティ(クラス、アクター、コンポーネントなど)の相互作用を時系列に沿って表現するものです

Entity

シーケンスに表示されるentityにはparticipantとactorがある

participantはシーケンス内の具体的な参加者や要素を表し、actorは外部からシステムに対話する主体を表す

```mermaid
sequenceDiagram
participant Participant
actor Actor
```

Aliaces

participant、actorにラベルを付与できる

```mermaid
sequenceDiagram
participant p as Participant
actor a as Actor
```

Messages

2つのEntityをメッセージ付きでつなぐことができる

[Actor][Arrow][Actor]:Message text

いくつかの種類の線がある

```mermaid
sequenceDiagram
participant A
participant B

A->B:Solid line without arrow
A-->B:Dotted line without arrow
A->>B:Solid line with arrowhead
A-->>B: Dotted line with arrowhead
A-xB:Solid line with a cross at the end
A--xB:Dotted line with a cross at the end.
A-)B:Solid line with an open arrow at the end (async)
A--)B:Dotted line with a open arrow at the end (async)
```

Activations

あるシーケンスの開始から終了までをアクティベートして可視化できる

```mermaid
sequenceDiagram
participant A
participant B

A->>B: activate start
activate B
B-->>A: activate end
deactivate B
```

+-で簡易設定できる

```mermaid
sequenceDiagram
participant A
participant B

A->>B+: activate start
B-->>A-: activate end
```

Loops

シーケンス上でループを表現できる

```mermaid
sequenceDiagram
participant A
participant B

loop n times
A->>B: action
end
```

Alt

条件による分岐を表現できる

```mermaid
sequenceDiagram
participant A
participant B

alt plan x
A->>B: action X
else plan y
A->>B: action Y
else
A->>B: action Z
end
```

単一の条件の場合にはoptが使える

```mermaid
sequenceDiagram
participant A
participant B

opt plan x
A->>B: action X
end
```

Break

シーケンスの終了を示す場合にBreakが使える

```mermaid
sequenceDiagram
participant A
participant B

A->>B: access request
break no permission
B-->>A: reject
end
```

Sample

```mermaid
sequenceDiagram
participant User as User
participant App as Application
participant DB as Database
participant API as API Service
participant Notification as Notification Service

User->>App: Request for data
App->>DB: Query database
loop Data retrieval
DB-->>App: Send data
alt Data available
App->>User: Display data
else Data not available
App->>API: Request external data
API-->>App: Receive external data
App->>DB: Save external data
App->>User: Display external data
end
end

App->>Notification: Notify user
```