Pattern · Core

Builder

Construct a complex object step by step with a readable, chainable API — instead of a monster constructor full of flags.

Asked atAmazonGoogleUber
step 1 / 9
1/2The telescoping constructor
Burger
+ Burger(bun, patty, cheese,
lettuce, tomato, sauce)
The telescoping constructor
1new Burger("wheat", true, false, true, true, false, "bbq");
2// bun patty cheese ... which flag is which??
State
call siteunreadable 💥

A Burger with many optional parts forces a giant constructor — a wall of positional flags.