Skip to content

Commit 2bf411d

Browse files
committed
Large Class → Extracted tax and discount logic into BookingPricing.
1 parent 2a7095e commit 2bf411d

File tree

1 file changed

+28
-45
lines changed
  • examples/csharp/csharp-booking-01_base/src/Booking

1 file changed

+28
-45
lines changed

examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,35 @@
22

33
namespace CodelyTv.Booking
44
{
5-
public class BookingDetails
6-
{
7-
public BookingId Id { get; }
8-
public DateTime StartDate { get; }
9-
public DateTime EndDate { get; }
10-
public CustomerId CustomerId { get; }
11-
public CustomerName CustomerName { get; }
12-
public EmailAddress CustomerEmail { get; }
13-
public BookingType BookingType { get; }
14-
public DiscountType DiscountType { get; }
15-
public DiscountValue DiscountValue { get; }
16-
public TaxType TaxType { get; }
17-
public TaxValue TaxValue { get; }
18-
19-
public BookingDetails(
20-
BookingId id, DateTime startDate, DateTime endDate, CustomerId customerId,
21-
CustomerName customerName, EmailAddress customerEmail, BookingType bookingType,
22-
DiscountType discountType, DiscountValue discountValue, TaxType taxType, TaxValue taxValue)
5+
public class BookingPricing
236
{
24-
Id = id;
25-
StartDate = startDate;
26-
EndDate = endDate;
27-
CustomerId = customerId;
28-
CustomerName = customerName;
29-
CustomerEmail = customerEmail;
30-
BookingType = bookingType;
31-
DiscountType = discountType;
32-
DiscountValue = discountValue;
33-
TaxType = taxType;
34-
TaxValue = taxValue;
35-
}
7+
public DiscountType DiscountType { get; }
8+
public DiscountValue DiscountValue { get; }
9+
public TaxType TaxType { get; }
10+
public TaxValue TaxValue { get; }
3611

37-
public Booking(BookingDetails details)
38-
{
39-
this.id = details.Id;
40-
this.startDate = details.StartDate;
41-
this.endDate = details.EndDate;
42-
this.customerId = details.CustomerId;
43-
this.customerName = details.CustomerName;
44-
this.customerEmail = details.CustomerEmail;
45-
this.bookingType = details.BookingType;
46-
this.discountType = details.DiscountType;
47-
this.discountValue = details.DiscountValue;
48-
this.taxType = details.TaxType;
49-
this.taxValue = details.TaxValue;
50-
}
12+
public BookingPricing(DiscountType discountType, DiscountValue discountValue, TaxType taxType, TaxValue taxValue)
13+
{
14+
DiscountType = discountType;
15+
DiscountValue = discountValue;
16+
TaxType = taxType;
17+
TaxValue = taxValue;
18+
}
19+
20+
private readonly BookingPricing pricing;
21+
22+
public Booking(BookingId id, DateTime startDate, DateTime endDate, CustomerId customerId,
23+
CustomerName customerName, EmailAddress customerEmail, BookingType bookingType, BookingPricing pricing)
24+
{
25+
this.id = id;
26+
this.startDate = startDate;
27+
this.endDate = endDate;
28+
this.customerId = customerId;
29+
this.customerName = customerName;
30+
this.customerEmail = customerEmail;
31+
this.bookingType = bookingType;
32+
this.pricing = pricing;
33+
}
5134

5235
public BookingStatus StatusFor(DateTime date)
5336
{
@@ -64,4 +47,4 @@ public BookingStatus StatusFor(DateTime date)
6447
return BookingStatus.FINISHED;
6548
}
6649
}
67-
}
50+
}

0 commit comments

Comments
 (0)