From 2a7095e7560af8e3a3c38643dcecac17364b1903 Mon Sep 17 00:00:00 2001 From: EduardKrutii Date: Sun, 9 Feb 2025 20:47:29 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Long=20Parameter=20List=20=E2=86=92=20Intro?= =?UTF-8?q?duced=20a=20DTO=20(BookingDetails).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Booking/Booking.cs | 84 ++++++++++--------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs b/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs index 0a765eab..d7b47011 100644 --- a/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs +++ b/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs @@ -2,46 +2,52 @@ namespace CodelyTv.Booking { - public sealed class Booking + public class BookingDetails +{ + public BookingId Id { get; } + public DateTime StartDate { get; } + public DateTime EndDate { get; } + public CustomerId CustomerId { get; } + public CustomerName CustomerName { get; } + public EmailAddress CustomerEmail { get; } + public BookingType BookingType { get; } + public DiscountType DiscountType { get; } + public DiscountValue DiscountValue { get; } + public TaxType TaxType { get; } + public TaxValue TaxValue { get; } + + public BookingDetails( + BookingId id, DateTime startDate, DateTime endDate, CustomerId customerId, + CustomerName customerName, EmailAddress customerEmail, BookingType bookingType, + DiscountType discountType, DiscountValue discountValue, TaxType taxType, TaxValue taxValue) { - private readonly BookingId id; - private readonly DateTime startDate; - private readonly DateTime endDate; - private readonly CustomerId customerId; - private readonly CustomerName customerName; - private readonly EmailAddress customerEmail; - private readonly BookingType bookingType; - private readonly DiscountType discountType; - private readonly DiscountValue discountValue; - private readonly TaxType taxType; - private readonly TaxValue taxValue; + Id = id; + StartDate = startDate; + EndDate = endDate; + CustomerId = customerId; + CustomerName = customerName; + CustomerEmail = customerEmail; + BookingType = bookingType; + DiscountType = discountType; + DiscountValue = discountValue; + TaxType = taxType; + TaxValue = taxValue; + } - public Booking( - BookingId id, - DateTime startDate, - DateTime endDate, - CustomerId customerId, - CustomerName customerName, - EmailAddress customerEmail, - BookingType bookingType, - DiscountType discountType, - DiscountValue discountValue, - TaxType taxType, - TaxValue taxValue - ) - { - this.id = id; - this.startDate = startDate; - this.endDate = endDate; - this.customerId = customerId; - this.customerName = customerName; - this.customerEmail = customerEmail; - this.bookingType = bookingType; - this.discountType = discountType; - this.discountValue = discountValue; - this.taxType = taxType; - this.taxValue = taxValue; - } + public Booking(BookingDetails details) + { + this.id = details.Id; + this.startDate = details.StartDate; + this.endDate = details.EndDate; + this.customerId = details.CustomerId; + this.customerName = details.CustomerName; + this.customerEmail = details.CustomerEmail; + this.bookingType = details.BookingType; + this.discountType = details.DiscountType; + this.discountValue = details.DiscountValue; + this.taxType = details.TaxType; + this.taxValue = details.TaxValue; + } public BookingStatus StatusFor(DateTime date) { @@ -58,4 +64,4 @@ public BookingStatus StatusFor(DateTime date) return BookingStatus.FINISHED; } } -} +} \ No newline at end of file From 4d665bee1c3eb879af52d709de37fbee0066f204 Mon Sep 17 00:00:00 2001 From: EduardKrutii Date: Sun, 9 Feb 2025 21:13:50 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Large=20Class=20=E2=86=92=20Extracted=20tax?= =?UTF-8?q?=20and=20discount=20logic=20into=20BookingPricing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Booking/Booking.cs | 73 +++++++------------ 1 file changed, 28 insertions(+), 45 deletions(-) diff --git a/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs b/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs index d7b47011..67241602 100644 --- a/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs +++ b/examples/csharp/csharp-booking-01_base/src/Booking/Booking.cs @@ -2,52 +2,35 @@ namespace CodelyTv.Booking { - public class BookingDetails -{ - public BookingId Id { get; } - public DateTime StartDate { get; } - public DateTime EndDate { get; } - public CustomerId CustomerId { get; } - public CustomerName CustomerName { get; } - public EmailAddress CustomerEmail { get; } - public BookingType BookingType { get; } - public DiscountType DiscountType { get; } - public DiscountValue DiscountValue { get; } - public TaxType TaxType { get; } - public TaxValue TaxValue { get; } - - public BookingDetails( - BookingId id, DateTime startDate, DateTime endDate, CustomerId customerId, - CustomerName customerName, EmailAddress customerEmail, BookingType bookingType, - DiscountType discountType, DiscountValue discountValue, TaxType taxType, TaxValue taxValue) + public class BookingPricing { - Id = id; - StartDate = startDate; - EndDate = endDate; - CustomerId = customerId; - CustomerName = customerName; - CustomerEmail = customerEmail; - BookingType = bookingType; - DiscountType = discountType; - DiscountValue = discountValue; - TaxType = taxType; - TaxValue = taxValue; - } + public DiscountType DiscountType { get; } + public DiscountValue DiscountValue { get; } + public TaxType TaxType { get; } + public TaxValue TaxValue { get; } - public Booking(BookingDetails details) - { - this.id = details.Id; - this.startDate = details.StartDate; - this.endDate = details.EndDate; - this.customerId = details.CustomerId; - this.customerName = details.CustomerName; - this.customerEmail = details.CustomerEmail; - this.bookingType = details.BookingType; - this.discountType = details.DiscountType; - this.discountValue = details.DiscountValue; - this.taxType = details.TaxType; - this.taxValue = details.TaxValue; - } + public BookingPricing(DiscountType discountType, DiscountValue discountValue, TaxType taxType, TaxValue taxValue) + { + DiscountType = discountType; + DiscountValue = discountValue; + TaxType = taxType; + TaxValue = taxValue; + } + + private readonly BookingPricing pricing; + + public Booking(BookingId id, DateTime startDate, DateTime endDate, CustomerId customerId, + CustomerName customerName, EmailAddress customerEmail, BookingType bookingType, BookingPricing pricing) + { + this.id = id; + this.startDate = startDate; + this.endDate = endDate; + this.customerId = customerId; + this.customerName = customerName; + this.customerEmail = customerEmail; + this.bookingType = bookingType; + this.pricing = pricing; + } public BookingStatus StatusFor(DateTime date) { @@ -64,4 +47,4 @@ public BookingStatus StatusFor(DateTime date) return BookingStatus.FINISHED; } } -} \ No newline at end of file +}