ABOUT ME

Today
Yesterday
Total
  • TIL 54th day
    TIL(Today I Learned) 2021. 12. 16. 15:24

    비즈니스 로직 작성 Tip

    Data를 가지고 있는 class에 business logic을 설계하는것이 응집도에 좋다.

    Exception class 작성 Tip

    에러 메시지와 원인을 파악하도록 Override Method를 작성한다.
    ex)

    //NotEnoughStockException
    
    public NotEnoughStockException() {
            super();
        }
    
        public NotEnoughStockException(String message) {
            super(message);
        }
    
        public NotEnoughStockException(String message, Throwable cause) {
            super(message, cause);
        }
    
        public NotEnoughStockException(Throwable cause) {
            super(cause);
        }

    데이터 변경 시 비즈니스 로직 작성

    setter를 이용해서 변경하는것이 아닌, 핵심 비즈니스 로직을 작성해서 데이터를 변경하는것이 바람직하다.

    ex)

    //Item
    
        public void addStock(int quantity){
            this.stockQuantity += quantity;
        }
    
        public void removeStock(int quantity){
            int restStock = this.stockQuantity = quantity;
            if(restStock < 0){
                throw new NotEnoughStockException("need more stock");
            }
            this.stockQuantity = restStock;
        }

    'TIL(Today I Learned)' 카테고리의 다른 글

    JSP 커스텀 태그/웹 프로그램의 전반적인 흐름  (2) 2022.09.20
    TIL 55th day  (0) 2021.12.17
    TIL 53th day  (0) 2021.12.14
    TIL 52th day  (0) 2021.12.13
    TIL 51th day  (0) 2021.12.12
Designed by Tistory.