💻 개발IT/UML

3. Class Diagram

초겨울 2022. 2. 25. 18:38

UML Class Diagram

  • 두 가지로 사용
    • OOA, 도메인 모델로 사용 (단순)
    • OOD, 클래스 다이어그램 or DCD(Design class diagram)로 사용 (실제 코드 구현할 수 있도록 디테일하게)

 

UML Object Diagram

  • specific moment 시점에서 객체와 그 관계를 식별
  •  작성
    • Operation은 표현 X, 변수의 detail한 value까지 표현
    • 소문자로 시작 (클래스는 대문자)
    • Anonymous object : 현재 기준 object 이름이 없거나 지칭할 수 없을 때

 

Object에서 Class로

  • Attribute
    • 소문자로 시작
    • 형식
      • public : 다른 class의 object한테 보임 (operation default)
      • private : 보이지 않음 (attribute default)
        • getter, setter 함수 만들어줘야함
      • derived attribute : 이름 앞에 / 붙임. 다른 attribute와 association을 위해 계산된 것 
    • 타입
      • Data types
        • Primitive data type
          • Pre-defined : Boolean, Integer, Unlimited Natural, String...
          • User-defined : <<primitive>> (operation도 가능)
          • Composite data type(struct) : <<datatype>>
            • 위 두개는 아래 enumeration처럼 옆에 다가 정의해서 그려두면 됨
        • Enumerations: <<enumeration>>
      • User-defined classes
    • Multiplicity
      • default value : 1
      • Notation: [min..max]
    • default value 설정 가능 (아래 예시에서 password)
    • Properties

  • Operation
    • Parameters
      • in : input parameter
        • default
      • out : output parameter (보통 구현이 힘들어서 잘 안 씀)
      • inout : in/out parameter (보통 구현이 힘들어서 잘 안 씀)
    • vs. Method
      • class diagram에 작성하는 것은 operation임 (선언, 설계 수준)
      • Method는 c++, java 등에서 구현된 코드
  • Class Variable and Operation
    • Class에서만 사용하는 것 (:= static)
    • 밑줄 그으면 됨
  • Note Symbol
    • 우측에 접힌듯한 상자
    • 단순 comment 적거나 constraint 적거나 method body(구현할 수도 코드) 등을 적음

  • Relationship
    • dependency
      • 잠깐 같이 일하는 경우
    • Association (default)
      • 일정 시간동안 같이 일하는 경우
      • 화살표는 optional (default로 있다고 봄. 단, 한 쪽 방향에 화살표가 있다면 반대쪽은 X가 있다고 생각)
      • Navigability
        • 화살표 : Student는 Professor의 public한 것을 모두 볼 수 있다
        • X 표시 : Professor는 Student의 public, private 모두 못 봄
      • +lecturer은 Student 클래스 내부에 public Professor[] lecturer;이 있다는 것을 의미 
        • []인 것은 * 이기 때문

      • n-ary Association : 두 개 이상일 때
      • Association Class
        • Association에 class를 붙인 것
      • Singleton Class
        • instance가 1개 나올 때, 네모 우측 상단에 1을 적으면 됨
        • 가능하면 자주 사용하면 안 됨
      • Active Class
        • thread(독립적으로 움직임)가 되는 class
        • 선을 양쪽에 하나씩 더 그려주면 됨
      • Interface
        • 3가지 방법
          • Socket + lollipop 
          • Dependency line
          • Interface implementation (가장 많이 씀)
    • (Shared) Aggregation : 강화된 Association (약한 version)
      • 한 클래스가 다른 클래스의 part인 경우
        • B가 A를 가지고 있는 경우
      • 예시
        • LabClass가 0이라 해도 Student가 있을 수 있음
          • 만약 Composition일 경우 LabClass가 0이면 Student도 없어야함
    • Composition : 강화된 Association (강한 version)
      • 예시
    • Inheritance (Generalization)
      • superclass의 모든 association, aggregations도 내려받을 수 있음 (단, private는 제외)
      • Abstract Class
        • 이탤릭 체로 이름을 적거나 이름 상단에 {abstract} 작성

typical : (내부 외부 class가 고객을 generalization하고 order와 상품과 연결)

아래는 저자의 답 (특이한 version)   

 

 

 

반응형