A fluent interface lets method calls be chained into a sequence that reads like an instruction. In an Object Mother, customization methods return the Object Mother itself, so an order can be configured and then built in one expression. section 14.3
When choosing this style, weigh readability against implementation and debugging costs:
- Chaining can make configuration less verbose and help readers check whether the instructions fit the task. section 14.3
- A traditional interface remains an option; fluent methods require extra implementation code and can sometimes be harder to debug. section 14.3
Listing 14.11 Step definitions that use the object mother for building the order
*** StepDefinitions/OrderingStepDefinitions.cs ***
[Given("the customer has placed an order containing a {string} pizza")]
public void GivenTheCustomerHasPlacedAnOrderContaining(string pizzaName)
{
var order = new OrderObjectMother() #A
.WithItem(name: pizzaName)
.Build();
...
}
[When("the customer places an order for {int} pizza(s) of size {string}")]
public void WhenTheCustomerPlacesAnOrderFor(int count, string pizzaSize)
{
var order = new OrderObjectMother() #B
.WithItems(count, size: pizzaSize)
.Build();
...
}
[Given("the customer has placed an order")]
public void GivenTheCustomerHasPlacedAnOrder()
{
var order = new OrderObjectMother().Build(); #C
...
}The order-building calls chain customization methods before Build returns the configured order. section 14.3





