@startuml
class Foo1 {
You can use
several lines
..
as you want
and group
==
things together.
__
You can have as many groups
as you want
--
End of class
}
class User {
.. Simple Getter ..
+ getName()
+ getAddress()
.. Some setter ..
+ setName()
__ private data __
int age
-- encrypted --
String password
}
@enduml
注釈とステレオタイプ
ステレオタイプは、キーワード class に << と >> で定義されます。 注釈の定義には、キーワード note left of, <code>note right of</code>, note top of, note bottom of も使用できます。 クラス定義の最後には note left, note right, note top, note bottom も使用できます。 注釈は、キーワード note とで単独に定義することができ、記号 .. を使用して他のオブジェクトとリンクすることもできます。
@startuml
class Object << general >>
Object <|--- ArrayList
note top of Object : In java, every class\nextends this one.
note "This is a floating note" as N1
note "This note is connected\nto several objects." as N2
Object .. N2
N2 .. ArrayList
class Foo
note left: On last defined class
@enduml
注釈の詳細
次のようないくつかの HTML タグを使用することも可能です:
<b>
<u>
<i>
<s>, <del>, <strike>
<font color="#AAAAAA"> or <font color="colorName">
<color:#AAAAAA> or <color:colorName>
<size:nn> to change font size
<img src="file"> or <img:file>: the file must be accessible by the filesystem
@startuml
class Foo
note left: On last defined class
note top of Object
In java, <size:18>every</size> <u>class</u>
<b>extends</b>
<i>this</i> one.
end note
note as N1
This note is <u>also</u>
<b><color:royalBlue>on several</color>
<s>words</s> lines
And this is hosted by <img:sourceforge.jpg>
end note
@enduml
WARNING
This translation need to be updated.
WARNING
Note on field (field, attribut, member) or method
It is possible to add a note on field (field, attribut, member) or on method.
Note on field or method
@startuml
class A {
{static} int counter
+void {abstract} start(int timeout)
}
note right of A::counter
This member is annotated
end note
note right of A::start
This method is now explained in a UML note
end note
@enduml
Note on method with the same name
@startuml
class A {
{static} int counter
+void {abstract} start(int timeoutms)
+void {abstract} start(Duration timeout)
}
note left of A::counter
This member is annotated
end note
note right of A::"start(int timeoutms)"
This method with int
end note
note right of A::"start(Duration timeout)"
This method with Duration
end note
@enduml
リンク定義の直後に note on link を使用して、リンクに注釈を加えることが可能です。 もし注釈の相対位置を変えたい場合には、ラベル note left on link, note right on link, note top on link, note bottom on link も使用できます。
@startuml
class Dummy
Dummy --> Foo : A link
note on link #red: note that is red
Dummy --> Foo2 : Another link
note right on link #blue
this is my note on right link
and in blue
end note
@enduml
@startuml
class "This is my class" as class1
class class2 as "It works this way too"
class2 *-- "foo/dummy" : use
@enduml
属性、メソッド等の非表示
コマンド hide/show を使用して、クラスの表示をパラメータ化できます。 基本のコマンドは hide empty members です。このコマンドは属性やメソッドが空の場合に非表示にします。 empty members の代わりに使用することができます:
empty fields または empty attributes は空のフィールドに、
empty methods は空のメソッドに、
fields または attributes は、それらが記述されていても非表示になります、
methods はメソッドが記述されていても非表示になります、
members はフィールドとメソッドが記述されていても非表示になります、
circle はクラス名の前の丸で囲んだ文字に、
stereotype はステレオタイプに。
キーワード hide または show のすぐ後ろに提供することもできます:
class は全てのクラスに、
interface は全てのインタフェースに、
enum は全ての列挙型に、
<<foo1>> は foo1 でステレオタイプ化されたクラスに、
既存のクラス名。
コマンド show/hide をルールや例外の定義にそれぞれ使用することができます。
@startuml
class Dummy1 {
+myMethods()
}
class Dummy2 {
+hiddenMethod()
}
class Dummy3 <<Serializable>> {
String name
}
hide members
hide <<Serializable>> circle
show Dummy1 methods
show <<Serializable>> fields
@enduml
パッケージに利用可能なさまざまなスタイルがあります。 コマンド skinparam packageStyle を使用してデフォルトのスタイルを設定する、またはパッケージのステレオタイプを使用する、のどちらかで指定することができます。 or by using a stereotype on the package:
@startuml
scale 750 width
package foo1 <<Node>> {
class Class1
}
package foo2 <<Rectangle>> {
class Class2
}
package foo3 <<Folder>> {
class Class3
}
package foo4 <<Frame>> {
class Class4
}
package foo5 <<Cloud>> {
class Class5
}
package foo6 <<Database>> {
class Class6
}
@enduml
方向の最初の文字を使用して矢印を短縮することができます(例えば、-d- を -down- の代わりに、または、最初の 2 文字 (-do-)。 この機能を悪用してはならないことに注意してください。Graphviz は微調整のいらない良い結果を通常は与えてくれます。 left to right directionパラメータを使用した場合は次のようになります。
@startuml
left to right direction
foo -left-> dummyLeft
foo -right-> dummyRight
foo -up-> dummyUp
foo -down-> dummyDown
@enduml
関連クラス
この例のように、2 つのクラスの関係を定義した後で 関連クラス を定義することができます。
@startuml
class Student {
Name
}
Student "0..*" - "1..*" Course
(Student, Course) .. Enrollment
class Enrollment {
drop()
cancel()
}
@enduml
別の方向にそれを定義することができます:
@startuml
class Student {
Name
}
Student "0..*" -- "1..*" Course
(Student, Course) . Enrollment
class Enrollment {
drop()
cancel()
}
@enduml
Association on same classe
@startuml
class Station {
+name: string
}
class StationCrossing {
+cost: TimeInterval
}
<> diamond
StationCrossing . diamond
diamond - "from 0..*" Station
diamond - "to 0..* " Station
@enduml
@startuml
skinparam backgroundcolor AntiqueWhite/Gold
skinparam classBackgroundColor Wheat|CornflowerBlue
class Foo #red-green
note left of Foo #blue\9932CC
this is my
note on this class
end note
package example #GreenYellow/LightGoldenRodYellow {
class Dummy
}
@enduml
@startuml
class Bar1
class Bar2
together {
class Together1
class Together2
class Together3
}
Together1 - Together2
Together2 - Together3
Together2 -[hidden]--> Bar1
Bar1 -[hidden]> Bar2
@enduml
@startuml
class foo
foo --> bar
foo -[#red]-> bar1
foo -[#green]-> bar2
foo -[#blue]-> bar3
'foo -[#blue;#yellow;#green]-> bar4
@enduml
新しい書き方
@startuml
class foo
foo --> bar : normal
foo --> bar1 #line:red;line.bold;text:red : red bold
foo --> bar2 #green;line.dashed;text:green : green dashed
foo --> bar3 #blue;line.dotted;text:blue : blue dotted
@enduml
@startuml
left to right direction
class User {
id : INTEGER
..
other_id : INTEGER
}
class Email {
id : INTEGER
..
user_id : INTEGER
address : INTEGER
}
User::id *-- Email::user_id
@enduml