2020/05/06

PlantUMLでシーケンス図作成

背景


システムの詳細設計でシーケンス図を作成する必要があり、Gitで差分管理が可能なクラス図作成ツールを調査した。

記事の目的


PlantUMLでシーケンス図を作成する

シーケンス図


シーケンス図について記載する。

シーケンス図とは

シーケンス図は、クラスやオブジェクト間のやりとりを時間軸に沿って表現したものである。

シーケンス図の描き方

  • ライフライン(Lifeline)
  • @startuml
    participant Participant
    actor Actor
    database Database
    collections Collections
    @enduml
    使用するオブジェクトやクラスを表す。利用者(Actor)、オブジェクトやクラス(Participant)、データベース(Database)、集合(Collections)がある。
  • 実行仕様(ExecutionSpecification)
  • @startuml
    participant Participant
    Participant -> Participant: Activate
    activate Participant
    Participant -> Participant: Deactivate
    deactivate Participant
    @enduml
    生成されているライフラインが実行状態であることを表す。
  • 停止(Stop)
  • @startuml
    participant Participant
    activate Participant
    Participant -> Participant: Destroy
    destroy Participant
    @enduml
    生成されたライフライン自体の消滅を表す。
  • メッセージ(Message)
  • @startuml
    participant Client as c
    participant Server as s
    activate c
    c -> s : Synchronous message
    activate s
    s --> c: Reply message
    c ->> s: Asynchronous message
    [o->  s: Found message
    c ->o] : Lost message
    @enduml
    データやトリガーの通信を表す。
    • 同期(Synchronous)メッセージ
    • 送り先のライフラインの実行に同期されるメッセージを表す。
    • 非同期(Asynchronous)メッセージ
    • 送り先のライフラインの実行に同期されないメッセージを表す。
    • 応答(Reply)メッセージ
    • 送り先のライフラインから送り手への戻り値を表す。
    • ファウンド(Found)メッセージ
    • 図解上にない送り手から送られた、もしくは送り手がダイアグラム上にないことを表す。
    • ロスト(Lost)メッセージ
    • 意図された受け手に送られていない、もしくは受け手がダイアグラム上にないことを表す。
  • 参照(Reference)
  • @startuml
    participant Client as c
    participant Server as s
    activate c
    c -> s : Connect
    activate s
    c -> s : Login
    ref over s
        Check id and password
        sequence
    end ref
    s --> c: Result
    @enduml
    別で定義されてるシーケンス図を参照することを表す。
  • 条件分岐(Alternative)
  • @startuml
    participant Client as c
    participant Server as s
    activate c
    c -> s : Connect
    activate s
    c -> s : Login
    s -> s : Check ID and password
    alt ID and password are matched
        s --> c: Send token
    else not matched
        s --> c: Disconnect
    else ID is not exist
        s --> c: Disconnect
    end
    @enduml
    条件による処理の分岐を表す。
  • 条件判断(Option)
  • @startuml
    participant Client as c
    participant Server as s
    activate c
    c -> s : Connect
    activate s
    c -> s : Login
    s -> s : Check ID and password
    opt ID and password are matched
        s --> c: Send an authorized token
    end
    @enduml
    条件を満たす場合に処理を実行することを表す。
  • 並列処理(Parallel)
  • @startuml
    participant Client as c
    participant Server as s
    database    "Login record DB" as db
    activate c
    c -> s : Connect
    activate s
    c -> s : Login
    s -> s : Check ID and password
    opt ID and password are matched
        par
            s -> s : Create an authorized token
            s --> c: Send an authorized token
        else
            s -> db: Send login time
            activate db
            db -> db: Record login time
            deactivate db
        end
    end
    @enduml
    複数の処理を並列で実行することを表す。
  • 反復処理(Loop)
  • @startuml
    collections Client as c
    participant Server as s
    activate c
    activate s
    opt Time is 00:00
        loop Number of connected clients
            s -> c : Check client status
            c --> s: Send status
        end
    end
    @enduml
    処理を反復実行することを表す。
  • 中断(Break)
  • @startuml
    collections Client as c
    participant Server as s
    activate c
    activate s
    opt Time is 00:00
        loop Number of connected clients
            s -> c : Check client status
            c --> s: Send status
            break Client status is illegal
                loop Number of connected clients
                    s -> c : Disconnect
                end
            end
        end
    end
    @enduml
    反復処理中に特定の条件を満たした場合、(決められた処理を行い)反復処理を中止することを表す。
  • クリティカルセッション(Critical)
  • @startuml
    participant Client as c
    participant Server as s
    database    "Login record DB" as db
    activate c
    c -> s : Connect
    activate s
    c -> s : Login
    s -> s : Check ID and password
    opt ID and password are matched
        par
            s -> s : Create an authorized token
            s --> c: Send an authorized token
            s -> db: Send an authorized token
            critical
                activate db
                db -> db: Record an authorized token
                deactivate db
            end
        else
            s -> db: Send login time
            critical
                activate db
                db -> db: Record login time
                deactivate db
            end
        end
    end
    @enduml
    並列処理中に、排他制御された処理を表す。
  • アサート(Assert)
  • @startuml
    participant Client as c
    participant Server as s
    database    "Deposit record DB" as db
    activate c
    activate s
    c -> s : Send transfer information
    group assert 
    s -> db: Update deposit amount
    note right : Deposit amount = Transfer amount + Previous deposit amount
    activate db
    db -> db: Record deposit amount
    deactivate db
    end
    @enduml
    処理結果の妥当性を保証しなければならないことを表す。
  • 不正なシーケンス(Negative)
  • @startuml
    participant Client as c
    participant Server as s
    database    "Deposit record DB" as db
    activate c
    activate s
    c -> s : Send transfer information
    alt Deposit amount = Transfer amount + Previous deposit amount 
        s -> db: Update deposit amount
        activate db
        db ->db: Record deposit amount
        s --> c: Send accept msg
        deactivate db
    else Deposit amount != Transfer amount + Previous deposit amount 
        group neg
            s -->c : Send error msg
        end
    end
    @enduml
    処理が通常起こりえない処理である(異常系である)ことを表す。
  • 無効(Ignore)
  • @startuml
    participant Client as c
    participant Server as s
    activate c
    c -> s : Connect
    activate s
    group ignore {Send client status}
    c -> s : Login(Send id, password)
    c -> s : Send client status
    end
    s -> s : Check ID and password
    alt ID and password are matched
        s --> c: Send token
    else not matched
        s --> c: Disconnect
    end
    @enduml
    必須ではない処理を{}内に記載する。
  • 有効(Consider)
  • @startuml
    participant Client as c
    participant Server as s
    activate c
    c -> s : Connect
    activate s
    group consider {Login(Send id, password)}
    c -> s : Login(Send id, password)
    c -> s : Send client status
    end
    s -> s : Check ID and password
    alt ID and password are matched
        s --> c: Send token
    else not matched
        s --> c: Disconnect
    end
    @enduml
    必須な処理を{}内に記載する。
  • セクション(Section)
  • @startuml
    participant Client as c
    participant Server as s
    activate c
    == Make connection ==
    c -> s : Connect
    activate s
    == Login ==
    c -> s : Login
    ref over s
        Check id and password
        sequence
    end ref
    s --> c: Result
    @enduml
    セクションで区切ると、処理をまとめて整理できる。
  • オブジェクト生成(Create)
  • @startuml
    participant parent as p
    activate p
    p -> p: Initial process
    create participant child as c
    p -> c: New
    @enduml
    オブジェクト(インスタンス)を生成していることを表す。

まとめ


  • PlantUMLでシーケンス図を作成する方法を調査、記載した

参考文献



変更履歴


  1. 2020/05/06: 新規作成

0 件のコメント:

コメントを投稿

MQTTの導入

背景 IoTデバイスの接続環境構築のため、MQTT(mosquitto)の導入を行った。 記事の目的 MQTT(mosquitto)をUbuntuに導入する mosquitto ここではmosquittoについて記載する。 MQTT MQTT(Message Qu...