D2Lang

[D2Lang] 9. D2의 UML 클래스의 사용법을 알아보자!

o0zrone 2023. 5. 7. 12:40
728x90

UML 클래스 다이어그램을 만들어 보겠습니다.

MyClass: {
  shape: class

  field: "[]string"
  method(a uint64): (x, y int)
}

다음과 같이 출력됨을 확인할 수 있습니다.

class shape의 내부에 있는 각 key: value는 필드 혹은 메소드를 말합니다.

필드의 value는 변수 타입이며 메소드의 경우는 반환 유형입니다.

class의 접근 제어자는 아래와 같이 나타낼 수 있습니다.

visibility prefix meaning

none public
+ public
- private
# protected

아래는 사용 예제입니다.

 

D2 Parser: {
  shape: class
.
  +reader: io.RuneReader
  readerPos: d2ast.Position

  -lookahead: "[]rune"

  \\#lookaheadPos: d2ast.Position

  +peek(): (r rune, eof bool)
  rewind()
  commit()

  \\#peekn(n int): (s string, eof bool)
}

"github.com/terrastruct/d2parser.git" -> D2 Parser

보시면 #인 protected만 /#을 쓰고있는데요.

그 이유는 #은 D2Lang에서 주석(comment)으로 사용되고 있기 때문입니다.

다음은 결과입니다.

이상으로 마치겠습니다.