Skip to content

Instantly share code, notes, and snippets.

public class Movie {
public Money calculateMovieFee(Screening screening) {
// 예외적인 케이스를 처리하기 위해 요금 계산 책임을 Movie가 수행
if (discountPolicy == null)
return fee;
// 기존 방식대로 요금 계산 책임을 discountPolicy가 수행
return fee.minus(discountPolicy.calculateDiscountAmount(screening));
}
}
class Something {
Parent parent;
public Something(Parent parent) {
this.parent = parent;
}
public void doing() {
parent.doing();
}
public class FixedFeeCondition implements FeeCondition {
@Override
public List<DateTimeInterval> findTimeINtervals(Call call) {
return Arrays.asList(call.getInterval());
}
}
public class DurationFeeCondition implements FeeCondition {
private Duration from;
private Duration to;
public DurationFeeCondition(Duration from, Duration to) {
this.from = from;
this.to = to;
}
@Override
public class DayOfWeekFeeCondition implements FeeCondition {
private List<DayOfWeek> dayOfWeeks = new ArrayList<>();
public DayOfWeekFeeCondition(DayOfWeek ... dayOfWeeks) {
this.dayOfWeeks = dayOfWeeks;
}
@Override
public List<DateTimeInterval> findTimeInterval(Call call) {
return call.getInterval().splitByDay()
public class DayOfWeekFeeCondition implements FeeCondition {
private List<DayOfWeek> dayOfWeeks = new ArrayList<>();
public DayOfWeekFeeCondition(DayOfWeek ... dayOfWeeks) {
this.dayOfWeeks = dayOfWeeks;
}
}
public class TimeOfDayFeeCondition implements FeeCondition {
private LocalTime from;
private LocalTime to;
public TimeOfDayFeeCondition(LocalTime from, LocalTime to) {
this.from = from;
this.to = to;
}
@Override
public class TimeOfDayFeeCondition implements FeeCondition {
private LocalTime from;
private LocalTime to;
public TimeOfDayFeeCondition(LocalTime from, LocalTime to) {
this.from = from;
this.to = to;
}
}
public class BasicRatePolicy implements RatePolicy {
private List<FeeRule> feeRules = new ArrayList<>();
public BasicRatePolicy(FeeRule ... feeRules) {
this.feeRules = Arrays.asList(feeRules);
}
@Override
public Money calculateFee(Phone phone) {
return phone.getCalls()
public class FeePerDuration {
private Money fee;
private Duration duration;
public FeePerDuration(Money fee, Duration duration) {
this.fee = fee;
this.duration = duration;
}
public Money calculate(DateTimeInterval interval) {