Java Zero to All All questionsPractise free
Interview questions › Design Patterns in Java › Creational Design Patterns

You see a Builder on a two-field DTO. What's your reaction, and when is a Builder genuinely warranted?

Level IV · SeniorCreational Design Patterns
Short answer

That's over-engineering — for two required fields a constructor or static factory reads more clearly and a builder just adds ceremony and a window for a half-built object.

Explanation

Builder earns its keep when there are many parameters with several optional, you want immutability, and you want cross-field validation to run once in build() before publishing. If mandatory fields matter, I'd note that Lombok's @Builder makes everything look optional, so I'd use a required constructor arg or a step builder where the compiler enforces order and required steps.

Common mistakes
  • Adding a Builder by habit everywhere.
  • Not using records or constructors for small value objects.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Creational Design Patterns.

Practise free

More on Creational Design Patterns