-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/#1' into develop
[update feature] chapter 01 sample code
- Loading branch information
Showing
8 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/study/book/object/ticket/model/Audience.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package study.book.object.ticket.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* 관람객 Model | ||
*/ | ||
@Getter @Setter | ||
@ToString | ||
public class Audience { | ||
private Bag bag; | ||
|
||
public Audience(Bag bag) { | ||
this.bag = bag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package study.book.object.ticket.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter @Setter | ||
@ToString | ||
public class Bag { | ||
private Long amount; | ||
private Invitation invitation; | ||
private Ticket ticket; | ||
|
||
/** | ||
* Bag Instance 의 상태는 | ||
* 현금과 초대장을 함께 보관하거나, 초대장 없이 보관하는 두가지 | ||
* 이 두가지를 인스턴스 생성 시점에 강제한다. | ||
* @param amount 현금 보유량 | ||
*/ | ||
public Bag(long amount) { | ||
this(null, amount); | ||
} | ||
|
||
/** | ||
* Bag 생성시 초대장과 현금보유량으로 생성규정 | ||
* | ||
* @param invitation 초대장 | ||
* @param amount 현금 보유량 | ||
*/ | ||
public Bag(Invitation invitation, long amount) { | ||
this.invitation = invitation; | ||
this.amount = amount; | ||
} | ||
|
||
public boolean hasInvitation() { | ||
return invitation != null; | ||
} | ||
|
||
public boolean hasTicket() { | ||
return ticket !=null; | ||
} | ||
|
||
public void minusAmount(Long amount) { | ||
this.amount -= amount; | ||
} | ||
|
||
public void plusAmount(Long amount) { | ||
this.amount += amount; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
package study.book.object.ticket.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter @Setter | ||
@ToString | ||
public class Invitation { | ||
private LocalDateTime when; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
package study.book.object.ticket.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter @Setter | ||
@ToString | ||
public class Ticket { | ||
private Long fee; | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/study/book/object/ticket/model/TicketOffice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package study.book.object.ticket.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* 매표소 Model | ||
*/ | ||
@ToString | ||
public class TicketOffice { | ||
private Long amount; | ||
private List<Ticket> tickets = new ArrayList<>(); | ||
|
||
public TicketOffice(Long amount, Ticket... tickets) { | ||
this.amount = amount; | ||
this.tickets.addAll(Arrays.asList(tickets)); | ||
} | ||
|
||
public Ticket getTicket() { | ||
return tickets.remove(0); | ||
} | ||
|
||
public void minusAmount(Long amount) { | ||
this.amount -= amount; | ||
} | ||
|
||
public void plusAmount(Long amount) { | ||
this.amount += amount; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/study/book/object/ticket/model/TicketSeller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package study.book.object.ticket.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter @Setter | ||
@ToString | ||
public class TicketSeller { | ||
private TicketOffice ticketOffice; | ||
|
||
public TicketSeller(TicketOffice ticketOffice) { | ||
this.ticketOffice = ticketOffice; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/study/book/object/ticket/service/Theater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package study.book.object.ticket.service; | ||
|
||
import study.book.object.ticket.model.Audience; | ||
import study.book.object.ticket.model.Ticket; | ||
import study.book.object.ticket.model.TicketSeller; | ||
|
||
public class Theater { | ||
private TicketSeller ticketSeller; | ||
|
||
public Theater(TicketSeller ticketSeller) { | ||
this.ticketSeller = ticketSeller; | ||
} | ||
|
||
public void enter(Audience audience) { | ||
if(audience.getBag().hasInvitation()) { | ||
Ticket ticket = ticketSeller.getTicketOffice().getTicket(); | ||
audience.getBag().setTicket(ticket); | ||
} else { | ||
Ticket ticket = ticketSeller.getTicketOffice().getTicket(); | ||
audience.getBag().minusAmount(ticket.getFee()); | ||
ticketSeller.getTicketOffice().plusAmount(ticket.getFee()); | ||
audience.getBag().setTicket(ticket); | ||
} | ||
} | ||
} |