Design Patterns · Junior · Question 15 of 75
When is the Builder pattern useful?
- ✓Correct answer: When an object is assembled step by step from many optional parts
- 2When you need to guarantee a single instance of a class
- 3When you need to notify subscribers about changes
Explanation
Instead of a constructor with ten parameters - a chain new QueryBuilder().select('id').where(...).limit(10).build(). Examples: SQL query builders (Knex), URL and config builders. In JS, passing an options object is often enough.