Skip to content

QuizNot attempted

When a builder helps

Which situation calls for the Builder pattern?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • An object with many optional parts, assembled step by step and validated at the end (queries, HTTP requests, test fixtures)
  • Builder replaces telescoping constructors (new Query(a, b, undefined, undefined, c)) with readable chained steps and a final build() that can validate
  • think Knex/Prisma query builders and test-data builders.
  • Not exactly one instance: that is Singleton.
  • Not incompatible interfaces: that is Adapter.
  • Not reacting to changes: that is Observer.