ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [UML] 클래스 다이어그램
    자바/기타 2021. 5. 7. 10:35

    클래스 다이어그램

    • 클래스의 구성요소 및 클래스간의 관계를 표현하는 UML
    • 클래스 다이어그램을 이용하면 의존관계를 명확하게 보여준다.

     

    클래스 다이어그램을 이용한 관계 표현

    Generalization (일반화)

    우리가 일반적으로 알고 있는 상속을 의미

    public class Board {
    	private String title;
        private String contents;
        private List<Comment> comments;
    }
    
    class SchedulerBoard extends Board {
    	private LocalDate startDate;
        private LocalDate endDate;
        
        pubic void validateDateLine() {
        	...
        }
    }

     

    Realization (실체화)

    interface에 있는 함수를 오버라이딩하여 실제 구현한 것

    public interface OpenCloseable {
        void open();
        void close();
    }
    
    public class Board implements OpenCloseable {
        public void open() {
            System.out.println("open method");
        }
    
        public void close() {
            System.out.println("close method");
        }
    }

     

    Dependency (의존)

    Dependency 참조는 함수 내에서 대상 클래스의 객체를 생성하거나 사용, 리턴받아 사용하는 것을 말한다.

    이 참조는 해당 클래스와의 관계를 계속 유지하지 않는다.

    함수의 호출이 끝나면 연관된 클래스와의 관계가 마무리 된다.

    public class Board {
    
        private String title;
    
        public String getTitleWithRanking(Ranking ranking) {
            return title + ranking.getRank();
        }
    }
    
    public class Ranking { 
        private int rank;
    
        public int getRank() {
            return rank;
        }
    }

     

    연관관계 (Association & Direct Association)

    다른 객체의 참조를 가지는 필드를 의미

    실선으로 표시되며 방향성이 존재하는 경우 화살표를 넣어 표시한다.

    public class Board {
    
        private List<Comment> comments;
    
        public void addComment(Comment comment) {
            comments.add(comment);
        }
    }
    
    public class Comment {
    
        private Board board;
    
        public void setBoard(Board board) {
            this.board = board;
            board.addComment(this);
        }
    }

     

    집합관계 (Aggregation & Composition)

    집약관계 (Aggregation)

    • class A가 class B를 멤버 변수로 가지고 있는 경우
    • class A가 전체 개념이고 class B가 부분의 개념이다.
    • 하지만 class A가 직접 class B를 생성하지 않는다.
    • Factory가 파괴되어도 FactoryAddOn은 독립적으로 남아있다. (라이프 사이클이 다르다)

    합성관계 (Composition)

    • class A가 class B를 멤버 변수로 가지고 있는 경우
    • class A가 전체 개념이고 class B가 부분의 개념이다.
    • class A가 직접 class B를 직접 new해서 생성한다.
    • Carrier가 파괴되면 Intercepter도 같이 파괴된다. (라이프 사이클이 같다)

    '자바 > 기타' 카테고리의 다른 글

    [책 리뷰] DDD START! 도메인 주도 설계 구현과 핵심 개념 익히기  (0) 2021.05.07
    [JAVA] Array 클래스  (0) 2021.04.30
    [JAVA] String 클래스  (0) 2021.04.30
    [JAVA] Map  (0) 2021.04.30
    [JAVA] 클래스의 구성 관계  (0) 2021.04.28

    댓글

Designed by Tistory.