Skip to content

Commit

Permalink
[update feature] 설계 품질 트레이드 오프 진행
Browse files Browse the repository at this point in the history
  • Loading branch information
creaton60 committed Jan 16, 2020
1 parent 94d2ed9 commit 7f23db2
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/study/book/object/movie/Movie.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import lombok.Setter;
import lombok.ToString;
import study.book.object.movie.condition.DiscountCondition;
import study.book.object.movie.condition.DiscountConditionType;
import study.book.object.movie.policy.DiscountPolicy;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -42,4 +44,43 @@ public void changeDiscountPolicy(DiscountPolicy discountPolicy) {
public List<DiscountCondition> getDiscountConditions() {
return Collections.unmodifiableList(discountConditions);
}

public Money calculateAmountDiscountedFee() {
if(movieType != MovieType.AMOUNT_DISCOUNT) {
throw new IllegalArgumentException();
}

return fee.minus(discountAmount);
}

public Money calculatePercentDiscountFee() {
if(movieType != MovieType.PERCENT_DISCOUNT) {
throw new IllegalArgumentException();
}

return fee.minus(fee.times(discountPercent));
}

public Money calculateNoneDiscountFee() {
if(movieType != MovieType.NONE_DISCOUNT) {
throw new IllegalArgumentException();
}

return fee;
}

public boolean isDiscountable(LocalDateTime whenScreened, int sequence) {
for(DiscountCondition condition : discountConditions) {
if(condition.getType() == DiscountConditionType.PERIOD) {
if(condition.isDiscountable(whenScreened.getDayOfWeek(), whenScreened.toLocalTime())) {
return true;
}
} else {
if(condition.isDiscountable(sequence)) {
return true;
}
}
}
return false;
}
}
10 changes: 10 additions & 0 deletions src/main/java/study/book/object/movie/ReservationAgency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package study.book.object.movie;

public class ReservationAgency {

public Reservation reserve(Screening screening, Customer customer, int audienceCount) {
Money fee = screening.calculateFee(audienceCount);

return new Reservation(customer, screening, fee, audienceCount);
}
}
25 changes: 25 additions & 0 deletions src/main/java/study/book/object/movie/Screening.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,29 @@ public class Screening {
private Movie movie;
private int sequece;
private LocalDateTime whenScreened;

public Screening(Movie movie, int sequence, LocalDateTime whenScreened) {
this.movie = movie;
this.sequece = sequence;
this.whenScreened = whenScreened;
}

public Money calculateFee(int audienceCount) {
switch (movie.getMovieType()) {
case AMOUNT_DISCOUNT:
if(movie.isDiscountable(whenScreened, sequece)) {
return movie.calculateAmountDiscountedFee().times(audienceCount);
}
break;
case PERCENT_DISCOUNT:
if(movie.isDiscountable(whenScreened, sequece)) {
return movie.calculatePercentDiscountFee().times(audienceCount);
}
break;
case NONE_DISCOUNT:
return movie.calculateNoneDiscountFee().times(audienceCount);
}

return movie.calculateNoneDiscountFee().times(audienceCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ public class DiscountCondition {
private DayOfWeek dayOfWeek;
private LocalTime startTime;
private LocalTime endTime;

public boolean isDiscountable(DayOfWeek dayOfWeek, LocalTime time) {
if(type != DiscountConditionType.PERIOD) {
throw new IllegalArgumentException();
}

return this.dayOfWeek.equals(dayOfWeek) &&
this.startTime.compareTo(time) <= 0 &&
this.endTime.compareTo(time) >=0;
}

public boolean isDiscountable(int sequence) {
if (type != DiscountConditionType.SEQUENCE) {
throw new IllegalArgumentException();
}
return this.sequence == sequence;
}
}

0 comments on commit 7f23db2

Please sign in to comment.