콩딱일상

도메인 모델 패턴 본문

카테고리 없음

도메인 모델 패턴

콩이캠퍼 2024. 10. 3. 15:01

복잡한 비즈니스 로직과 데이터 처리를 효과적으로 관리하기 위한 방법을 찾는 과정에서 비롯되었다.

모든 비즈니스 로직을 서비스 레이어 한곳에 구현하면 가독성이 떨어지고 유지보수하기 어려워지는 한계점이 나오게 된다.

서비스 레이어와 비즈니스 규칙 예

public class XXService {
    public void addItem(String id, String productNo, String productName, int quantity) {
        int size = Dao.selectItemSize(id);
        if (size > 10) {
            throw new RuntimeException("...");
        }
       ...
    }
}

 

도메인 모델 패턴

  • 데이터와 행위를 하나의 객체로 설계

 

 

 

public class XXService {
	public void addItem(String id, String productNo, String productName,
    					int quantity) {
    	XX xx = Dao.select(id);
        xx.addItem(productNo, productName, quantity);
        Dao.update(xx);
    }
}

public class XX {
	public void addItem(String productNo, String productName, int quantity) {
    	//
    }
}