Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/ticket/audience.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Bag } from './bag';
import { Ticket } from './ticket';

export class Audience {
private readonly bag: Bag;
constructor(private bag: Bag) {}

constructor(bag: Bag) {
this.bag = bag;
}

get getBag(): Bag {
return this.bag;
buy(ticket: Ticket): number {
return this.bag.hold(ticket);
}
}
21 changes: 13 additions & 8 deletions src/ticket/bag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ import { Invitation } from './invitation';
import { Ticket } from './ticket';

export class Bag {
private amount: number;

private invitation: Invitation;

private ticket: Ticket;

constructor(invitation: Invitation, amount: number) {
this.invitation = invitation;
this.amount = amount;
}
constructor(private invitation: Invitation, private amount: number) {}

public hasInvitation(): boolean {
return this.ticket != null;
Expand All @@ -28,4 +21,16 @@ export class Bag {
public plusAmount(amount: number) {
this.amount += amount;
}

public hold(ticket: Ticket) {
if (this.hasInvitation()) {
this.setTicket(ticket);
return 0;
}

this.setTicket(ticket);
this.minusAmount(ticket.getFee);

return ticket.getFee;
}
}
16 changes: 2 additions & 14 deletions src/ticket/theater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ import { Audience } from './audience';
import { TicketSeller } from './ticketSeller';

export class Theater {
private ticketSeller: TicketSeller;

constructor(ticketSeller: TicketSeller) {
this.ticketSeller = ticketSeller;
}
constructor(private ticketSeller: TicketSeller) {}

public enter(audience: Audience): void {
if (audience.getBag.hasInvitation()) {
const ticket = this.ticketSeller.getTicketOffice.getTicket;
audience.getBag.setTicket(ticket);
} else {
const ticket = this.ticketSeller.getTicketOffice.getTicket;
audience.getBag.minusAmount(ticket.getFee);
this.ticketSeller.getTicketOffice.plusAmount(ticket.getFee);
audience.getBag.setTicket(ticket);
}
this.ticketSeller.sellTo(audience);
}
}
9 changes: 1 addition & 8 deletions src/ticket/ticketOffice.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { Ticket } from './ticket';

export class TicketOffice {
private amount: number;

private tickets: Array<Ticket>;

constructor(amount: number, tickets: Array<Ticket>) {
this.amount = amount;
this.tickets = tickets;
}
constructor(private amount: number, private tickets: Array<Ticket>) {}

get getTicket(): Ticket {
return this.tickets.pop();
Expand Down
11 changes: 4 additions & 7 deletions src/ticket/ticketSeller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { TicketOffice } from './ticketOffice';
import { Audience } from './audience';

export class TicketSeller {
private readonly ticketOffice: TicketOffice;
constructor(private ticketOffice: TicketOffice) {}

constructor(ticketOffice: TicketOffice) {
this.ticketOffice = ticketOffice;
}

get getTicketOffice(): TicketOffice {
return this.ticketOffice;
sellTo(audience: Audience) {
this.ticketOffice.plusAmount(audience.buy(this.ticketOffice.getTicket));
}
}