클래스 다이어그램
클래스 다이어그램은 시스템의 정적 구조를 표현합니다. 클래스, 그 속성과 메서드, 그리고 클래스 간의 관계를 기술하며, 코드의 구성과 설계를 문서화하는 데 가장 널리 사용되는 UML 다이어그램입니다. PlantUML에서는 구문이 프로그래밍 언어와 유사하므로, 속성, 메서드, 가시성 기호를 자연스럽게 작성할 수 있습니다. 관계를 나타내는 화살표는 시퀀스 다이어그램과 동일한 스타일을 사용합니다.- 텍스트 입력, 다이어그램 출력. 클래스, 필드, 관계를 몇 줄로 선언합니다.
- 코드처럼 읽힙니다.
+,-,#은 가시성,:은 타입,()은 메서드를 나타냅니다. - 자유롭게 주석을 답니다. 노트, 색상, 스테레오타입을 텍스트 안에서 그대로 작성할 수 있습니다.
Declarative element
|
🎉 Copied!
|
|
[Ref. for
protocol and struct: GH-1028; for exception: GH-1056, QA-16258; for metaclass and stereotype: GH-1159, QA-16784; for record and dataclass: GH-2232]
클래스 관계
클래스 관계는 다음과 같은 부호를 사용합니다.
| 유형 | 기호 | 목적 |
| 확장 |
<|--
|
계층 구조에서 클래스의 특수화 |
| 구현 |
<|..
|
클래스에 의한 인터페이스의 실현 |
| 컴포지션 |
*--
|
부분이 전체 없이는 존재할 수 없음 |
| 집합 |
o--
|
부분이 전체와 독립적으로 존재할 수 있음 |
| 의존성 |
-->
|
객체가 다른 객체를 사용함 |
| 약한 의존성 |
..>
|
더 약한 형태의 의존성 |
-- 는 .. 점선으로 대체 가능합니다.
이러한 규칙들로 다음과 같은 다이어그램을 그리는 것이 가능합니다.
|
🎉 Copied!
|
|
|
🎉 Copied!
|
|
|
🎉 Copied!
|
|
WARNING
This translation need to be updated. WARNING
관계를 나타내기 위한 레이블
관계에서 레이블을 추가하기 위해서는 뒤에 : 를 붙이고 레이블을 작성하면 됩니다.
관계차수를 나타내기 위해서는 ""를 이용하여 관계의 양쪽 끝에 작성하면 됩니다.
|
🎉 Copied!
|
|
< 또는 >을 사용하여 객체가 다른 객체에 대한 흐름 관계를 더 자세히 설명할 수 있습니다.
|
🎉 Copied!
|
|
Using non-letters in element names and relation labels
If you want to use non-letters in the class (or enum...) display name, you can either :
- Use the
askeyword in the class definition to assign an alias - Put quotes
""around the class name
|
🎉 Copied!
|
|
If an alias is assigned to an element, the rest of the file must refer to the element by the alias instead of the name.
Starting names with $
Note that names starting with $ cannot be hidden or removed later, because hide and remove command will consider the name a $tag instead of a component name. To later remove such elements they must have an alias or must be tagged.
|
🎉 Copied!
|
|
Also note that names starting with $ are valid, but to assign an alias to such element the name must be put between quotes "".
Adding methods
To declare fields and methods, you can use the symbol
: followed by the field's or method's name.
The system checks for parenthesis to choose between methods and fields.
|
🎉 Copied!
|
|
It is also possible to group between brackets
{} all fields and methods.
Note that the syntax is highly flexible about type/name order.
|
🎉 Copied!
|
|
You can use
{field} and {method} modifiers to
override default behaviour of the parser about fields and methods.
|
🎉 Copied!
|
|
메소드, 필드 가시화(Visibility) 정의
메소드나 필드들을 정의할 때, 특수문자를 사용하여 관련된 아이템을 가시화할 수 있습니다.
명령어는 다음과 같습니다:
| Character | Icon for field | Icon for method | Visibility |
-
|
|
|
private |
#
|
|
|
protected |
~
|
|
|
package private |
+
|
|
|
public |
|
🎉 Copied!
|
|
skinparam classAttributeIconSize 0를 사용하여, 아이콘 표시를 끌 수 있습니다.
명령어는 다음과 같습니다:
|
🎉 Copied!
|
|
*[Ref. [QA-4755](https://forum.plantuml.net/4755/provide-display-visibility-attributes-private-protected)]*
WARNING
This translation need to be updated. WARNING
Visibility on compositions and aggregations
|
🎉 Copied!
|
|
[Ref. QA-8294]
Abstract and Static
You can define static or abstract methods or fields using the {static}
or {abstract} modifier.
These modifiers can be used at the start or at the end of the line.
You can also use {classifier} instead of {static}.
|
🎉 Copied!
|
|
Advanced class body
By default, methods and fields are automatically regrouped by PlantUML.
You can use separators to define your own way of ordering fields and methods.
The following separators are possible : -- .. == __.
You can also use titles within the separators:
|
🎉 Copied!
|
|
Notes and stereotypes
Stereotypes are defined with the class keyword, << and >>.
You can also define notes using note left of , <code>note
right of</code> , note top of , note bottom of
keywords.
You can also define a note on the last defined class using note left, note right,
note top, note bottom.
A note can be also define alone with the note
keywords, then linked to other objects using the .. symbol.
|
🎉 Copied!
|
|
WARNING
This translation need to be updated. WARNING
More on notes
It is also possible to use few HTML tags (See Creole expression) like :
<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
note left, note right,
note top, note bottom.
|
🎉 Copied!
|
|
Note on field (field, attribute, member) or method
It is possible to add a note on field (field, attribute, member) or on method.
⚠ Constraint
- This cannot be used with
toporbottom(onlyleftandrightare implemented) - This cannot be used with namespaceSeparator
::
Note on field or method
|
🎉 Copied!
|
|
Note on method with the same name
|
🎉 Copied!
|
|
[Ref. QA-3474 and QA-5835]
Note on links
It is possible to add a note on a link, just after the link definition, using note on link.
You can also use note left on link, note right on link, note top on link,
note bottom on link if you want to change the relative position of the note with the label.
|
🎉 Copied!
|
|
Abstract class and interface
<a name="enum" id="enum">You can declare a class as abstract using "abstract"
or "abstract class" keywords.</a>
The class will be printed in italic.</p>
You can use the interface, annotation and enum keywords too.</p>
|
🎉 Copied!
|
|
*[Ref. 'Annotation with members' [Issue#458](https://github.com/plantuml/plantuml/issues/458)]*
WARNING
This translation need to be updated. WARNING
Hide attributes, methods...
You can parameterize the display of classes using the hide/show
command.
The basic command is: hide empty members. This
command will hide attributes or methods if they are empty.
Instead of empty members, you can use:
empty fieldsorempty attributesfor empty fields,empty methodsfor empty methods,fieldsorattributeswhich will hide fields, even if they are described,methodswhich will hide methods, even if they are described,memberswhich will hide fields and methods, even if they are described,circlefor the circled character in front of class name,stereotypefor the stereotype.
hide or show
keyword:
classfor all classes,interfacefor all interfaces,enumfor all enums,<<foo1>>for classes which are stereotyped with foo1,- an existing class name.
show/hide commands to define rules and
exceptions.
|
🎉 Copied!
|
|
You can also mix with visibility:
|
🎉 Copied!
|
|
[Ref. QA-2913]
Hide classes
You can also use the show/hide commands to hide classes.
This may be useful if you define a large !included file,
and if you want to hide some classes after file inclusion.
|
🎉 Copied!
|
|
Remove classes
You can also use the remove commands to remove classes.
This may be useful if you define a large !included file,
and if you want to remove some classes after file inclusion.
|
🎉 Copied!
|
|
Hide, Remove or Restore tagged element or wildcard
You can put $tags (using $) on elements, then remove, hide or restore components either individually or by tags.
By default, all components are displayed:
|
🎉 Copied!
|
|
But you can:
hide $tag13components:
|
🎉 Copied!
|
|
- or
remove $tag13components:
|
🎉 Copied!
|
|
- or
remove $tag13 and restore $tag1components:
|
🎉 Copied!
|
|
- or
remove * and restore $tag1components:
|
🎉 Copied!
|
|
Hide or Remove unlinked class
By default, all classes are displayed:
|
🎉 Copied!
|
|
But you can:
hide @unlinkedclasses:
|
🎉 Copied!
|
|
- or
remove @unlinkedclasses:
|
🎉 Copied!
|
|
[Adapted from QA-11052]
Use generics
You can also use bracket < and > to define generics usage in a class.
|
🎉 Copied!
|
|
It is possible to disable this drawing using
skinparam genericDisplay old command.
Specific Spot
Usually, a spotted character (C, I, E or A) is used for classes,
interface, enum and abstract classes.
But you can define your own spot for a class when you define the stereotype,
adding a single character and a color, like in this example:
|
🎉 Copied!
|
|
Packages
You can define a package using the
package keyword, and optionally declare a background color
for your package (Using a CSS color code or name).
Note that package definitions can be nested.
|
🎉 Copied!
|
|
Packages style
There are different styles available for packages.
You can specify them either by setting a default style with the command : skinparam packageStyle,
or by using a stereotype on the package:
|
🎉 Copied!
|
|
You can also define links between packages, like in the following example:
|
🎉 Copied!
|
|
Namespaces
Starting with version 1.2023.2, PlantUML handles differently namespaces and packages.
There won't be any difference between namespaces and packages anymore: both keywords are now synonymous.
Automatic namespace creation
You can define another separator (other than the dot) using
the command : set namespaceSeparator ???.
|
🎉 Copied!
|
|
You can disable automatic package creation using the command
set namespaceSeparator none.
|
🎉 Copied!
|
|
WARNING
This translation need to be updated. WARNING
Lollipop interface
You can also define lollipops interface on classes, using the following
syntax:
bar ()- foobar ()-- foofoo -() bar
|
🎉 Copied!
|
|
Changing arrows orientation
By default, links between classes have two dashes -- and are vertically oriented.
It is possible to use horizontal link by putting a single dash (or dot) like this:
|
🎉 Copied!
|
|
You can also change directions by reversing the link:
|
🎉 Copied!
|
|
It is also possible to change arrow direction by adding
left, right, up
or down keywords inside the arrow:
|
🎉 Copied!
|
|
You can shorten the arrow by using only the first character of the direction (for example,
-d- instead of
-down-)
or the two first characters (-do-).
Please note that you should not abuse this functionality : Graphviz gives usually good results without tweaking.
And with the left to right direction parameter:
|
🎉 Copied!
|
|
Association classes
You can define association class after that a relation has been
defined between two classes, like in this example:
|
🎉 Copied!
|
|
You can define it in another direction:
|
🎉 Copied!
|
|
Association on same class
|
🎉 Copied!
|
|
[Ref. Incubation: Associations]
Skinparam
You can use the skinparam
command to change colors and fonts for the drawing.
You can use this command :
- In the diagram definition, like any other commands,
- In an included file,
- In a configuration file, provided in the command line or the ANT task.
|
🎉 Copied!
|
|
Skinned Stereotypes
You can define specific color and fonts for stereotyped classes.
|
🎉 Copied!
|
|
Important: unlike class stereotypes, there must be no space between the skin parameter and the following stereotype. Any of the spaces shown as
_ below will cause all skinparams to be ignored,
see discord discussion
and issue #1932:
BackgroundColor_<<Foo>> Wheatskinparam stereotypeCBackgroundColor_<<Foo>> DimGray
Color gradient
You can declare individual colors for classes, notes etc using the # notation.
You can use standard color names or RGB codes in various notations, see Colors.
You can also use color gradient for background colors, with the following syntax:
two colors names separated either by:
|,/,\, or-
|
🎉 Copied!
|
|
Help on layout
Sometimes, the default layout is not perfect...
You can use together keyword to group some classes together :
the layout engine will try to group them (as if they were in the same package).
You can also use hidden links to force the layout.
|
🎉 Copied!
|
|
대용량 파일 분할하기
Sometimes, you will get some very large image files.
You can use the page (hpages)x(vpages) command to
split the generated image into several files :
hpages is a number that indicated the number of horizontal pages,
and vpages is a number that indicated the number of vertical pages.
You can also use some specific skinparam settings to put borders on splitted pages (see example).
|
🎉 Copied!
|
|
Extends and implements
It is also possible to use extends and implements keywords.
|
🎉 Copied!
|
|
|
🎉 Copied!
|
|
[Ref. QA-2239]
Bracketed relations (linking or arrow) style
Line style
It's also possible to have explicitlybold, dashed, dotted, hidden or plain relation, links or arrows:- without label
|
🎉 Copied!
|
|
- with label
|
🎉 Copied!
|
|
[Adapted from QA-4181]
Line color
|
🎉 Copied!
|
|
Line thickness
|
🎉 Copied!
|
|
[Ref. QA-4949]
Mix
|
🎉 Copied!
|
|
Change relation (linking or arrow) color and style (inline style)
You can change the color or style of individual relation or arrows using the inline following notation:
#color;line.[bold|dashed|dotted];text:color
|
🎉 Copied!
|
|
[See similar feature on deployment]
Change class color and style (inline style)
You can change the color or style of individual class using the two following notations:
#color ##[style]color
#color), then line style and line color (##[style]color )
|
🎉 Copied!
|
|
[Ref. QA-1487]
#[color|back:color];header:color;line:color;line.[bold|dashed|dotted];text:color
|
🎉 Copied!
|
|
First original example:
|
🎉 Copied!
|
|
[Ref. QA-3770]
Arrows from/to class members
|
🎉 Copied!
|
|
[Ref. QA-3636]
|
🎉 Copied!
|
|
[Ref. QA-5261]
Grouping inheritance arrow heads
You can merge all arrow heads using the skinparam groupInheritance, with a threshold as parameter.
GroupInheritance 1 (no grouping)
|
🎉 Copied!
|
|
GroupInheritance 2 (grouping from 2)
|
🎉 Copied!
|
|
GroupInheritance 3 (grouping only from 3)
|
🎉 Copied!
|
|
GroupInheritance 4 (grouping only from 4)
|
🎉 Copied!
|
|
[Ref. QA-3193, and Defect QA-13532]
Display JSON Data on Class or Object diagram
Simple example
|
🎉 Copied!
|
|
[Ref. QA-15481] For another example, see on JSON page.
Packages and Namespaces Enhancement
[From V1.2023.2+, and V1.2023.5]
|
🎉 Copied!
|
|
|
🎉 Copied!
|
|
|
🎉 Copied!
|
|
|
🎉 Copied!
|
|
[Ref. GH-1352]
Qualified associations
Minimal example
|
🎉 Copied!
|
|
[Ref. QA-16397, GH-1467]
Another example
|
🎉 Copied!
|
|
Change diagram orientation
You can change (whole) diagram orientation with:
top to bottom direction(by default)left to right direction
Top to bottom (by default)
With Graphviz (layout engine by default)
The main rule is: Nested element first, then simple element.
|
🎉 Copied!
|
|
With Smetana (internal layout engine)
The main rule is the opposite: Simple element first, then nested element.
|
🎉 Copied!
|
|
Left to right
With Graphviz (layout engine by default)
|
🎉 Copied!
|
|
With Smetana (internal layout engine)
|
🎉 Copied!
|
|
Role label to associations
|
🎉 Copied!
|
|
[Ref. GH-2536, GH-2537]