1. SOLID
SRP (Single Responsibility Principle) - 단일 클래스는 한 가지 기능만을 수행한다.
OCP (Open/Closed Principle) - 기능을 확장할 때 기존 클래스 코드의 수정이 없음.
LSP (Liskov Substitution Principle) - 프로그램의 객체가 서브 타입으로 교체될 수 있다.
ISP (Interface Segregation Principle) - 인터페이스는 클라이언트의 니즈에 따라 세분화되어야 하고, 클라이언트는 본인이 사용하지 않는 인터페이스에 종속되지 않음.
DIP (Dependency Inversion Principle) - 고수준 모델은 저수준 모델에 의존하지 않음.
2. 코드 리팩토링
public boolean validateOrder(Order order) {
boolean isValid = true;
if (isOrderEmpty(order)) {
log.info("주문 항목이 없습니다.");
isValid = false;
}
if (isOrderPriceInvalid(order) {
log.info("올바르지 않은 총 가격입니다.");
isValid = false;
}
if (!order.hasCustomerInfo()) {
log.info("사용자 정보가 없습니다.");
isValid = false;
}
return isValid;
}
private static boolean isOrderEmpty(Order order) {
return order.isEmpty()
}
private static boolean isOrderPriceInvalid(Order order) {
return order.getTotalPrice() <= 0
}