
Spring을 개발할 때, 클래스명과 디렉토리 구조를 어떻게 설계할지 고민할 필요가 있다.
클래스 이름은 보통 "도메인(Domain)명" + "레이어(Layer)명" 으로 구성
| 클래스명 | 도메인 | 레이어 |
|---|---|---|
PaymentService | Payment | Service |
UserRepository | User | Repository |
JobpostController | Jobpost | Controller |
이 규칙을 따르면 코드를 보자마자 이 클래스가 어떤 도메인을 다루고 있고, 어떤 역할을 하는지 쉽게 알 수 있음.
Spring 프로젝트에서 클래스를 어떤 기준으로 디렉토리에 배치할 것인가에 대한 두가지 방식
/exception/
/advisor/
/controller/
├── user/
├── payment/
├── cart/
├── jobpost/
├── delivery/
/service/
/repository/
/configuration/
장점
service를 찾거나, repository를 찾을 때 빠르게 접근 가능.이 방식의 단점
controller, service, repository)가 여러 폴더에 흩어져 있어서 관리가 어려울 수도 있음.controller, service, repository)가 한 폴더에 들어 있음/user/
├── controller/
├── service/
├── repository/
/payment/
├── controller/
├── service/
├── repository/
/cart/
/jobpost/
/delivery/
장점
controller, service, repository)가 한 폴더 안에 모여 있어서 관리가 편리함.단점
service 폴더를 찾으려면 각 도메인의 폴더를 뒤져야 함.