The Builder pattern is often praised for its ability to create complex objects in a clean, readable, and flexible way.
But there’s a trap: if your builder requires manually setting every single field with no sensible defaults, it turns into an anti-pattern.

What a Good Builder Should Do

A good builder should make object creation:

  • Easy for the user by offering defaults for optional fields.
  • Safe by making required fields explicit (you must set them before you can build).
  • Clear by improving readability compared to long constructors or static factories.

The point is to improve usability and maintainability. Without defaults and validation, the builder adds more code and ceremony without giving any real benefits.

Example

Person person = new PersonBuilder()
.name("Alice")
.age(30)
.email("alice@example.com")
.address("123 Street")
.phone("1234567890")
.build();

In this case:

  • No enforcement of mandatory fields. If one field is missing, you would have invalid person object.
  • You could achieve the same thing (with less code) using a constructor or a static factory.

The builder becomes noise instead of help.

Simply put, you don’t ever need builder unless it very necessary to simplify complex objection creation and the Builder must provide:

  • Defaults for optional fields.
  • Clear enforcement of required fields.

A builder should simplify object creation — not make it harder.

Leave a comment