이전 글(https://nkdev.tistory.com/193)
에서 설계한 도메인 구조를 클래스 다이어그램으로 만들어보자!

그리고 뼈대만 코드로 구현해보았다.
예전에는 하염없이 인텔리제이를 보다가... 목적도 없이 3 tier architecture부터 만들어나갔는데 😓
OOP 설계를 하니까 사용자 요구사항에 대한 로직을 바로 구현할 수 있어서 좋다.
package movie.domain;
import java.time.Duration;
public class Movie {
private String title;
private Duration runningTime;
private long basePrice;
public Movie(String title, Duration runningTime, long basePrice) {
this.title = title;
this.runningTime = runningTime;
this.basePrice = basePrice;
}
}
package movie.domain;
import java.util.List;
/**
* 예매 정보를 나타내는 클래스. 예매 성공 시 생성되어 영수증과 같은 역할을 합니다.
*/
public class Reservation {
private Screening screening;
private List<Seat> reservedSeats;
private long totalPrice;
public Reservation(Screening screening, List<Seat> reservedSeats, long totalPrice) {
this.screening = screening;
this.reservedSeats = reservedSeats;
this.totalPrice = totalPrice;
}
}
package movie.domain;
import java.time.LocalDateTime;
import java.util.List;
public class Screening {
private Movie movie;
private LocalDateTime startTime;
private List<Seat> seats;
public Screening(Movie movie, LocalDateTime startTime, List<Seat> seats) {
this.movie = movie;
this.startTime = startTime;
this.seats = seats;
}
public Reservation reserve(User user, List<Seat> seatsToReserve) {
// TODO: 예매 로직 구현
// 1. 좌석 예매 가능 여부 확인
// 2. 예매 정보 생성
// 3. Reservation 객체 반환
return null;
}
}
package movie.domain;
public class Seat {
private char row;
private int col;
private SeatGrade grade;
private boolean isReserved;
public Seat(char row, int col, SeatGrade grade) {
this.row = row;
this.col = col;
this.grade = grade;
this.isReserved = false;
}
public boolean isAvailable() {
return !isReserved;
}
public void reserve() {
this.isReserved = true;
}
}
package movie.domain;
public enum SeatGrade {
S,
A,
B
}
package movie.domain;
public class User {
private long points;
public User(long points) {
this.points = points;
}
public void managePoints() {
// TODO: 포인트 관리 로직 구현
}
}
package movie.policy;
import movie.domain.Reservation;
public interface DiscountPolicy {
/**
* 할인을 적용하고 할인된 금액을 반환합니다.
*
* @param reservation 할인 대상 예매 정보
* @return 할인 금액
*/
long calculateDiscountAmount(Reservation reservation);
}
'프로젝트' 카테고리의 다른 글
| 동시성 제어 방법 - 비관적 락, 낙관적 락 (0) | 2025.10.15 |
|---|---|
| 모놀리식 아키텍처와 MSA / 동기 처리와 비동기 처리 / MQ (0) | 2025.10.13 |
| [Next Step 사전과제] 도메인 설계(2) - 도메인 규칙 정의 (0) | 2025.09.18 |
| [Next Step 사전과제] 도메인 설계(1) - 행동과 책임 (1) | 2025.09.18 |
| (6) Swagger 어노테이션 정리 (0) | 2025.03.30 |