Presentation
Application
Domain Service
Infrastructure
Command Query Responsibility Segregation
명령 기능과 쿼리 기능을 위한 모델을 구분하는 패턴
public interface ProductRecommendationService {
List<Product> getRecommendationsOf(ProductId productId);
}
public class RecommendationSystemClient implements ProductRecommendationService {
private ProductRepository productRepository;
@Override
public List<Product> getRecommendationsOf(ProductId productId) {
List<RecommendationItem> items = getRecommendationItems(id.getValue());
return toProducts(items);
}
private List<RecommendationItem> getRecommendationItems(String itemId) {
// externalRecommendationClient는 외부 추천 시스템을 위한 클라이언트
return externalRecommendationClient.getRecommendationItems(itemId);
}
private List<Product> toProducts(List<RecommendationItem> items) {
return items.stream()
.map(item -> toProductId(item.getItemId()))
.map(productId -> productRepository.findById(productId))
.toList();
}
private ProductId toProductId(String itemId) {
return new ProductId(itemId);
}
}
Open Host Service
Anti Corruption Layer