DEV Community

Discussion on: Builder Design Pattern

Collapse
 
helpermethod profile image
Oliver Weiler • Edited

I prefer Java 8 style builders

Burger.of(14, ingredients -> ingredients
    .pepperoni()
    .lettuce()
    .tomato());

You can easily create an overload which accepts only the mandatory arguments

Burger.of(14);

The configuration is implemented as a Consumer of type T, where T is a some sort of configuration object.

See Molten JSON for a JSON Builder implemented that way.