Here's an example implementation of a fluent builder for a basket class in C#:
main.cs1430 chars72 lines
This code defines a BasketBuilder
class that exposes fluent methods to add items and discounts to a new Basket
instance. The Basket
class itself has properties for calculating the total and final prices of the basket, as well as methods to add items and apply discounts.
Here's an example of how to use the BasketBuilder
to create a basket:
main.cs136 chars6 lines
This code creates a new Basket
instance with two apple items, one orange item, and a 10% discount, and assigns it to the basket
variable.
gistlibby LogSnag