unhurried

コンピュータ関連ネタがほとんど、ときどき趣味も…

PlantUML Class Diagram

I made a class diagram with PlantUML followed by the previou sequence diagram.

' Write comments after single quotaion mark.

@startuml

' Color Setting
skinparam classBorderColor black
skinparam classArrowColor black
skinparam noteBorderColor black
skinparam classAttributeIconSize 0

' Class Definition
class ClassA {
  - privateMember : Integer
  + publicMember : Integer
  # protectedMember : Integer
  ~ packageMember : Integer
  + method() : void
  + {static} staticMethod() : void
  + {abstract} abstractMethod() : void
}
' Note (For Class)
note top of ClassA: Note
note right of ClassA
  Note
end note

' Interface
interface Interface
ClassA ..|> Interface
' Note(Linkに対して)
note on link: Note

' Abstract Class
abstract AbstractClass
ClassA --|> AbstractClass

' Association
ClassA -- ClassB

' Composition
ClassA --* ClassC

' Aggregation
class ClassD
ClassA --o ClassD

' Dependency
class ClassE
ClassA ..> ClassE

@enduml

Generated Diagram

http://www.plantuml.com/plantuml/png/XLBBIiD05DtdAowuy4N5jGj1MnU2kl4B9fCn3ardmcHKV5H80gBetiVEZLR5AheGeTIF6OhT-GlUIL9R9M0Mayavvzuvzqp6mIIl9hqsAQx79duooPlT9yycVJ09VjwRj6FI8xjQwjQoSRlNFJFnGxzrqVzuDl6bIKuTVCQXV_BIRptssbTELESY98eqW0OaYXQbyfYgoa0gS0D2wty52qh9dN9UICt-hzTQSNTBisKgnJhVOp1h3TaPqZkJlAEdp-wTascXcbN0lWDGWL3nRQBPAckuJC4SB0lDVAQGcuPmomquBQ76i0njKSsy4lOGGhH8_FAc3QOtfJSnYV2sv5w6xKUQQ4wRaBzNooJ4ZRGYL3TXiFihQ-B4QsZhgtESZOXtr7lgclZSn3TVdHF79WbQXY0tYWpcCdrEAEvlwY65XsOS4rvs1JPEEuRQ89GvVB0RmOfOPsOEvaVG7qihNDHB7Ka10NA55onOAERBdJY3SN_m72wEgrJmkD-CRH55adBCKegXCE-tQFcgR8Gouh_vgLnGpHhulc9-tc3ahwaDrNA0eBh6Gio92RexAbuQHZ9V8Dy0

PlantUML クラス図

前回のシーケンス図に続いてクラス図も作成してみました。

' コメントはシングルクオーテーションの後に記述する

@startuml

' 色設定
skinparam classBorderColor black
skinparam classArrowColor black
skinparam noteBorderColor black
skinparam classAttributeIconSize 0

' クラス定義
class ClassA {
  - privateMember : Integer
  + publicMember : Integer
  # protectedMember : Integer
  ~ packageMember : Integer
  + method() : void
  + {static} staticMethod() : void
  + {abstract} abstractMethod() : void
}
' Note(Classに対して)
note top of ClassA: Note
note right of ClassA
  Note
end note

' Interface
interface Interface
ClassA ..|> Interface
' Note(Linkに対して)
note on link: Note

' Abstract Class
abstract AbstractClass
ClassA --|> AbstractClass

' Association
ClassA -- ClassB

' Composition
ClassA --* ClassC

' Aggregation
class ClassD
ClassA --o ClassD

' Dependency
class ClassE
ClassA ..> ClassE

@enduml

生成される図

http://www.plantuml.com/plantuml/png/XLBBIiD05DtdAowuy4N5jGj1MnU2kl4B9fCn3ardmcHKV5H80gBetiVEZLR5AheGeTIF6OhT-GlUIL9R9M0Mayavvzuvzqp6mIIl9hqsAQx79duooPlT9yycVJ09VjwRj6FI8xjQwjQoSRlNFJFnGxzrqVzuDl6bIKuTVCQXV_BIRptssbTELESY98eqW0OaYXQbyfYgoa0gS0D2wty52qh9dN9UICt-hzTQSNTBisKgnJhVOp1h3TaPqZkJlAEdp-wTascXcbN0lWDGWL3nRQBPAckuJC4SB0lDVAQGcuPmomquBQ76i0njKSsy4lOGGhH8_FAc3QOtfJSnYV2sv5w6xKUQQ4wRaBzNooJ4ZRGYL3TXiFihQ-B4QsZhgtESZOXtr7lgclZSn3TVdHF79WbQXY0tYWpcCdrEAEvlwY65XsOS4rvs1JPEEuRQ89GvVB0RmOfOPsOEvaVG7qihNDHB7Ka10NA55onOAERBdJY3SN_m72wEgrJmkD-CRH55adBCKegXCE-tQFcgR8Gouh_vgLnGpHhulc9-tc3ahwaDrNA0eBh6Gio92RexAbuQHZ9V8Dy0

PlantUML Sequence Diagram

I made a sample sequence diagramAtom with PlantUML. Most frequently used rules are in this sample, so you should be able to make your own diagrams by modifying this sample if you forget the rules.

' Writes comments after singl quotaion mark.

@startuml

' Color Setting
skinparam actorBorderColor black
skinparam sequenceParticipantBorderColor black
skinparam sequenceLifeLineBorderColor black
skinparam sequenceArrowColor black
skinparam noteBorderColor black

' Declaire participants.
' You can define an alias usibg "as".
actor Actor as A
participant Participant as P

A -> P : Synchronous Message
activate P
A <<-- P : Return Message
deactivate P

A ->> P : Asynchronous Message
A -> A : Message to Self

' Note (For messages)
A -> P : Message
note right
 Note: note (left|right) ... end note
 (Or just "note (left|right) : ...")
end note
' Note (For participants)
note over A, P : note (left|rigght|over) of

' Text Decoration
A -> P : Multi Line\n(Line Break)
A -[#blue]> P : <font color="blue"><b>Change Style</b></font>

' Conditional Branch
alt guard condition
  A -> P : Message
else guard condition
  A -> P : Message
end

' "Message to Self" doesn't work with "Activate" well.
A ->> P : Asynchronous Message
activate P
P -> P : Message to Self
deactivate P

@enduml

Generated Diagram

http://www.plantuml.com/plantuml/png/ZLDTJnD157tVNt5J7qeJAUzDRRBmwaSZZ-h3T3kbQzSPd9t5aF3Wx2gsLW8nGTJW0o58XT0IJDH4g3zcM5YV-0lEJB4k7udTPAUxzvwUUy-vTxCWmwyosf2HEfjIz6JuNJ-7-pBQbQ5wtP7HeOmMzQbJspehkd7_ZHIxIUTzycjVYWyoR5lgoaBIEaWwUt7te-KtN3AB67e2oE6KJL9MnMoAUfH1nKDE8mNmyTC04mUN4UEkuyuYmaU1ttPhwYPu5ApD67rsFOHGVWs5qf9gHolkRYQTvsU7pTDrSRgw5I_takZexB2bWCYNOZjkRiKhIp9ygyIVzh-eY1HBsXSZ7snp8XziQ_OVRxg6JfOjouRn4fIX0DFpnAapIcZWmnti-sW6Qovt3d6iW3OKY-FZ1daVyu2H8QYAKp33Do2q_MiOJJbRPSy3m2bCOw-c3RYhd562ppDgtd6lByMQ59-rxc6ZVwcqaS3ScJgtp5yBnbeOyt2DBvXu3lBvF61IDHaBnkunU1pu739NaGMDpUIi8NhOpuMvNEWfE-Y1pc5b-4tJt4LYnRoWipcWHk79krVntbgo-VBtPZybAF2u2tgr7f8n_GEJ3AD6JYCUtAXu0Nuq01PhLCtDqMjpAwFZcLAnKfgg8wACdERp7YvEL4h52GqhcNgVDev_VekRY_71YeKy3ZC1ObN5GAekTocn0AxOYZqVZuGZLLtYqXpL9ssVRuCKdUCVhqzQRIcMu_RgyT6wCMv7YXV_svBKGfKlrHqkJ7hj_W00

PlantUML シーケンス図

AtomでPlantUMLを編集する環境が整ったので、今回はシーケンス図のサンプルを作成しました。よく使いそうな記法を網羅するようにしていますので、記法を忘れていてもこのサンプルを修正しながら図を記述していくことができると思います。

' コメントはシングルクオーテーションの後に記述する

@startuml

' 色設定
skinparam actorBorderColor black
skinparam sequenceParticipantBorderColor black
skinparam sequenceLifeLineBorderColor black
skinparam sequenceArrowColor black
skinparam noteBorderColor black

' Participantの宣言(省略可能)
' asで別名を定義できる
actor Actor as A
participant Participant as P

A -> P : Synchronous Message
activate P
A <<-- P : Return Message
deactivate P

A ->> P : Asynchronous Message
A -> A : Message to Self

' Note(Messageに対して)
A -> P : Message
note right
 Note: note (left|right) ... end note
 (Or just "note (left|right) : ...")
end note
' Note(Participantに対して)'
note over A, P : note (left|rigght|over) of

' 文字装飾
A -> P : Multi Line\n(Line Break)
A -[#blue]> P : <font color="blue"><b>Change Style</b></font>

' 条件分岐
alt guard condition
  A -> P : Message
else guard condition
  A -> P : Message
end

' Message to SelfはActivateと上手く動作しない
A ->> P : Asynchronous Message
activate P
P -> P : Message to Self
deactivate P

@enduml

生成される図

http://www.plantuml.com/plantuml/png/ZLDTJnD157tVNt5J7qeJAUzDRRBmwaSZZ-h3T3kbQzSPd9t5aF3Wx2gsLW8nGTJW0o58XT0IJDH4g3zcM5YV-0lEJB4k7udTPAUxzvwUUy-vTxCWmwyosf2HEfjIz6JuNJ-7-pBQbQ5wtP7HeOmMzQbJspehkd7_ZHIxIUTzycjVYWyoR5lgoaBIEaWwUt7te-KtN3AB67e2oE6KJL9MnMoAUfH1nKDE8mNmyTC04mUN4UEkuyuYmaU1ttPhwYPu5ApD67rsFOHGVWs5qf9gHolkRYQTvsU7pTDrSRgw5I_takZexB2bWCYNOZjkRiKhIp9ygyIVzh-eY1HBsXSZ7snp8XziQ_OVRxg6JfOjouRn4fIX0DFpnAapIcZWmnti-sW6Qovt3d6iW3OKY-FZ1daVyu2H8QYAKp33Do2q_MiOJJbRPSy3m2bCOw-c3RYhd562ppDgtd6lByMQ59-rxc6ZVwcqaS3ScJgtp5yBnbeOyt2DBvXu3lBvF61IDHaBnkunU1pu739NaGMDpUIi8NhOpuMvNEWfE-Y1pc5b-4tJt4LYnRoWipcWHk79krVntbgo-VBtPZybAF2u2tgr7f8n_GEJ3AD6JYCUtAXu0Nuq01PhLCtDqMjpAwFZcLAnKfgg8wACdERp7YvEL4h52GqhcNgVDev_VekRY_71YeKy3ZC1ObN5GAekTocn0AxOYZqVZuGZLLtYqXpL9ssVRuCKdUCVhqzQRIcMu_RgyT6wCMv7YXV_svBKGfKlrHqkJ7hj_W00

PlantUML How to Install

What is PlantUML?

  • A Language (DSL) to write UML in a text format.
  • Supported diagrams:
    • Sequence diagram
    • Sequence diagram
    • Use case diagram
    • Class diagram
    • Activity diagram
    • Component diagram
    • State diagram
    • Object diagram
    • Deployment diagram (Beta)
    • Timing diagram (Beta)

Try It On Website

Set up an environment to use PlantUML with Atom (Windows10)

  1. Install Graphviz
  2. Run Atom and install the PlantUML plugin
    • Select from the menu: File -> Settings -> Install.
    • Search for "plantuml-viewer" and install it.
  3. Change the Settings of PlantUML Plugin
    • Select from the menu: File -> Settings -> Packages -> plantuml-viewer -> Settings.
      • Charset: UTF-8
      • Graphviz Dot Executable: C:\Program Files (x86)\Graphviz2.38\bin\dot.exe (When you installed Graphviz with default settings.)

PlantUML インストール方法

これまでUMLを記述するのには、仕事でも個人でもastah* communityを利用していました。astah* communityはバージョン7.0から商用利用不可となりましたが、私のUMLの用途はシステムの概要を説明するために簡単なクラス図とシーケンス図を使っていただけでしたので、有料版を購入するほどのものでもありません。そこでその代替となるツールを探してみることにしました。

Qiitaで人気そうなのはテキストでUMLを記述できるPlantUMLというツールでした。少し使ってみたところ、記法はシンプルで覚えやすく、テキストのために差分比較もでき、Atomプラグインを利用することでリアルタイムプレビューもできるため、中々使いやすいと感じました。大規模の図では探したい場所をテキスト中から探すのにが大変になるかもしれませんが、私の用途では全く困らなそうです。

以下では、PlantUMLのインストール方法を簡単にご紹介しています。

PlantUML

  • UMLをテキストで記述するための言語(DSL
  • 対応しているUMLのダイアグラム
    • シーケンス図
    • ユースケース
    • クラス図
    • アクティビティ図
    • コンポーネント
    • ステートマシン図
    • オブジェクト図
    • 配置図(ベータ版)
    • タイミング図(ベータ版)

Webサイトで簡単に試す

Atomでの編集環境を構築する(Windows10)

  1. Graphvizをインストールする

  2. Atomを起動してPlantUMLプラグインをインストールする

    • メニューから File -> Settings -> Install を選択します。
    • 「plantuml-viewer」を検索してインストールします。
  3. PlantUMLプラグインの設定を更新する

    • メニューから File -> Settings -> Packages -> plantuml-viewer -> Settings を選択します。
      • Charset: UTF-8
      • Graphviz Dot Executable: C:\Program Files (x86)\Graphviz2.38\bin\dot.exe (Graphvizをデフォルト設定のままインストールした場合)

Assign Zone Apex Domain to AWS ELB (ALB)

What is zone apex?

Zone apex means a simplest domain, which is not a sub domain. For example, if we own a domain "example.com", "www.example.com" is not a zone apex, but "example.com" is a zone apex.

CNAME can not be configured to zone apex

If we use a DNS server outside AWS instead of using Route53, which is a DNS service from AWS, we need to configure the domain name of ELB(ALB) as CNAME record of the domain. However, this configuration may not work correctly because it violates the specification written in RFC1912.

Use an alias record of Route 53

Consequently we can't use outside DNS servers in this case, and have to use the function provided by Route53 which is called "alias record". Alias records can be configured like CNAME records, and behave like A records. (Route53 will resolve the IP address of the CNAME record and return the IP address as an A record response.)

Reference