# Builder Pattern

> Making a big object one step at a time. At the end you call build.

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** Builder Design Pattern, Fluent Builder

## Think of it like

It is like ordering a sandwich step by step. Bread, then filling, then sauce, then wrap it up.

## Definition

The builder pattern makes a complex object step by step instead of all at once. A builder object has one method for each part you might set. You call the ones you need, often chained in one line, then call build. The builder checks the parts and hands back the finished object. It replaces long constructors with many arguments that are easy to mix up.

## Example

Lucy's code makes web requests with a builder. She sets the address, adds a header and a timeout, then calls build.

## Example code

```javascript
const request = new RequestBuilder()
  .url("https://example.com/api/orders")
  .header("Accept", "application/json")
  .timeout(5000)
  .build();
```

Each line sets one part. build() checks them and makes the request.

## Why it matters

Code that makes objects reads like a list of choices. Bad mixes are caught in one place, in build.

## Common mistake

Using a builder for a small object with two fields. A plain constructor is shorter and just as clear.

## Three principles

- **Step by step.** One part at a time.
- **Build at the end.** Check, then make.
- **No long argument lists.** Named steps instead.

## Related terms

- [Design Pattern](https://learn.benibix.com/term/development/design-pattern)
- [Factory Pattern](https://learn.benibix.com/term/development/factory-pattern)
- [Object (Programming)](https://learn.benibix.com/term/development/object)
- [Class](https://learn.benibix.com/term/development/class)

![Four small panels. Decorator: a reader box wrapped inside a cache layer, wrapped inside a log layer, all with the same read method. Builder: three steps, url, header and timeout, then build, making one finished request. Facade: one place order box in front of three parts, stock, payment and shipping. Repository: app code asks a user repository for a user, and only the repository talks to the database.](https://learn.benibix.com/diagrams/dev6-more-patterns.svg)

---

Source: https://learn.benibix.com/term/development/builder-pattern
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
