Ayden's journal

UML 클래스 다이어그램 in D2

스테레오타입

UML에서 스테레오타입(stereotype)은 클래스, 관계, 속성, 메서드 등에 추가적인 의미를 부여하기 위해 사용된다. 스테레오타입은 <<>>로 감싸서 표기합니다. 다양한 스테레오타입이 있지만, 대표적인 몇 가지는 다음과 같다.

classOne: className {
  shape: class
}

classTwo: <<abstract>>\nclassName {
  shape: class
}

classThree: <<interface>>\nclassName {
  shape: class
}

classFour: <<singleton>>\nclassName {
  shape: class
}

 

접근 제어자

UML에서는 접근 제어자를 나타내기 위해 + - #을 사용한다. 이는 각각 public private protected를 나타낸다. static 접근 제어자의 경우 밑줄을 치고, readonly일 때는 {final}을 붙이곤 한다. D2에서는 이 두 방식을 지원하지 않으므로, 나는 보통 꺾쇄를 통해 표기한다.

className {
  shape: class

  +publicVar: string
  -privateVar: <static, final> string
  \#protectedVar: string

  +publicMethod(str string): void
  -privateMethod(str string): void
  \#protectedMethod(str string): void
}

 

관계

// Generalization ( 일반화, 상속 )
class -> <<abstract>> {
  target-arrowhead {
    shape: triangle
  }
}

// Realization ( 실체화, 구현 )
class -> <<interface>> {
  style.stroke-dash: 5
  
  target-arrowhead {
    shape: triangle
  }
}

// Dependency ( 의존 )
// method 내부에서 사용하고 바로 소멸
class -> anotherClass or interface: publicMethod {
  style.stroke-dash: 5
  
  target-arrowhead {
    shape: arrow
  }
}

// Association ( 연관 )
// 
class -- anotherClass or interface {
  target-arrowhead: 1
  source-arrowhead: 0 .. *
  
  target-arrowhead {
    shape: arrow // 방향성이 존재하는 경우에만
  }
}

// Composition ( 합성 )
// 생애주기를 함께함. 생성자에서 인스턴트 생성 (constructor)
전체 <-> 부분 {
  source-arrowhead {
    shape: diamond
    style.filled: true
  }

  target-arrowhead {
    shape: arrow
  }
}

// Aggregation ( 집합 )
// 생애주기를 함께하지 않음. 생성자의 변수로 인스턴트를 받아옴 (constructor)
전체 <-> 부분 {
  source-arrowhead {
    shape: diamond
    style.filled: false
  }

  target-arrowhead {
    shape: arrow
  }
}

 

블로그의 정보

Ayden's journal

Beard Weard Ayden

활동하기