inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[워밍업 클럽 3기 BE code] 1주차

infoqoch
0

워밍업 클럽 3기 BE를 시작한 이유

 

미션2. 추상과 구체

- 물을 끓인다.

- 원두를 간다.

- 컵 위에 드리퍼를 올리고, 드리퍼 위에 필터를 둔다.

- 필터 위에 원두 가루를 담고 평탄화 한다.

- 다 끓은 물을 드립 포트에 담고, 원두 가루가 파이지 않도록 조심스럽게 드립 포트의 물을 드리퍼에 가득 채운다.

- 물이 다 빠지면 다시 물을 채운다. 총 세 번 물을 채운다.

 

미션3-1 리팩토링

@Slf4j
public class Order {
    private List<Item> items;
    private Customer customer;

    public boolean validateOrder() {
        if (isEmptyItem()) {
            log.info("주문 항목이 없습니다.");
            return false;
        }

        if (isInvalidTotalPrice()) {
            log.info("올바르지 않은 총 가격입니다.");
            return false;
        }

        if (isCustomerInfoMissing()) {
            log.info("사용자 정보가 없습니다.");
            return false;
        }

        return true;
    }

    private boolean isCustomerInfoMissing() {
        return customer == null;
    }

    private boolean isInvalidTotalPrice() {
        return getTotalPrice() > 0;
    }

    private boolean isEmptyItem() {
        return items == null || items.isEmpty();
    }

    private int getTotalPrice() {
        return items.stream()
                .map(Item::getPrice)
                .reduce(0, Integer::sum);
    }
}

class Item {
    private int price;

    public int getPrice() {
        return price;
    }
}

class Customer {}

 

미션 3-2 SOLID

 

이번 주 소감

 

답변 0