Builder

Intent: Separate the construction of a complex object from its representation so the same process can create different representations.

When to use it

  • Objects have many optional parts
  • Step-by-step construction reads better than a giant constructor

Example

Building a quote line by line: scope, items, taxes, terms.

Code sketch (TypeScript)

new QuoteBuilder().client(c).add('Concept', 25000).gst(18).terms(t).build();

Learn patterns step by step in the Learn area →