Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

A domain class has six constructors with different parameter combinations and callers mix them up. What alternatives do you propose and what are their trade-offs?

Six telescoping constructors are hard to read and easy to misuse, especially when several parameters share a type. I would offer named static factory methods, such as Order.forCustomer(...), which make intent clear and can return cached or subtype instances; a builder when there are many optional parameters, at the cost of an extra class and validation at run time instead of compile time; or a record with a compact constructor when the class is plain data. Whatever we pick, every path should chain to one canonical constructor so the validation lives in one place.

Why this question is asked

Constructors are the entry point to every object, and when a class has many of them, the cost shows up in every caller: wrong arguments in the right types, defaults nobody remembers, and validation that differs depending on which constructor was used. Interviewers ask this design question because there is no single right answer; they want to hear the alternatives, what each one costs, and how we would choose for a specific class. In this answer, we will see why telescoping constructors cause bugs, then look at static factories, builders and records in turn, and finish with the rule that ties them together: one canonical constructor.

1The Problem With Telescoping Constructors

Telescoping constructors are a family where each constructor adds one or two parameters to the previous one. They grow naturally: the class starts with Order(customerId), someone adds a currency, then a warehouse, a discount and an express flag, and soon there are six.

Java
public Order(long customerId) { ... }
public Order(long customerId, String currency) { ... }
public Order(long customerId, String currency, long discountCents) { ... }
public Order(long customerId, long warehouseId) { ... }
public Order(long customerId, long warehouseId, String currency, long discountCents) { ... }
public Order(long customerId, long warehouseId, String currency, long discountCents, boolean express) { ... }
new Order(42, 7); // customer 42, warehouse 7: correct, but only the author knows it
new Order(7, 42); // compiles too: customer 7, warehouse 42, a silent bug
new Order(42, "EUR", 500); // is 500 a discount in cents, or something else?

Notice the two problems. Readers cannot tell what the arguments mean without opening the class, and parameters of the same type, here several longs, can be swapped without any compile error. On top of that, each constructor may set defaults and validate slightly differently, so an Order built one way can be invalid while the same Order built another way is rejected.

2Option 1: Named Static Factory Methods

A static factory method is a static method that returns an instance. Unlike constructors, it has a name, so the call says what kind of object we are creating.

Java
public final class Order {
public static Order forCustomer(long customerId) {
return new Order(customerId, DEFAULT_WAREHOUSE, "USD", 0, false);
}
public static Order expressFrom(long customerId, long warehouseId) {
return new Order(customerId, warehouseId, "USD", 0, true);
}
private Order(long customerId, long warehouseId, String currency, long discountCents, boolean express) {
// the one canonical constructor, see below
}
}
Order o = Order.expressFrom(42, 7); // intent is clear at the call site

Factories also have abilities constructors lack. They can return a cached instance instead of a new one, as Integer.valueOf does for small values, and they can return a subtype, as List.of does by choosing different internal classes depending on the number of elements. The cost is that factories are less discoverable than constructors in an IDE, and they still have positional parameters, so a factory with four longs has the same swapping problem. They work best when the class has a few well-known ways to be created.

3Option 2: A Builder for Many Optional Parameters

When there are many optional parameters, a builder lets callers set only what they need, by name, in any order.

Java
Order o = Order.builder()
.customerId(42)
.warehouseId(7)
.currency("EUR")
.discountCents(500)
.build(); // validation happens here
public static final class Builder {
private long customerId = -1, warehouseId = DEFAULT_WAREHOUSE, discountCents;
private String currency = "USD";
private boolean express;
public Builder customerId(long v) { customerId = v; return this; }
public Builder warehouseId(long v) { warehouseId = v; return this; }
public Builder currency(String v) { currency = v; return this; }
public Builder discountCents(long v) { discountCents = v; return this; }
public Builder express(boolean v) { express = v; return this; }
public Order build() {
if (customerId < 0) throw new IllegalStateException("customerId is required");
return new Order(customerId, warehouseId, currency, discountCents, express);
}
}

Every argument is named, so swapping warehouse and customer becomes visible in the code. The costs are real, though. The builder is an extra class to write and maintain (or generate with a tool such as Lombok). A forgotten required field is only detected when build() runs, so a check that the compiler did for constructors becomes a run-time exception, which tests must cover. And there is a small allocation for the builder object, which matters only on very hot paths. A common compromise is to take required values in the builder's factory method, Order.builder(customerId), and leave only optional ones as setters.

4Option 3: A Record With a Compact Constructor

If Order is really plain data, a set of values with no hidden state, a record gives us one canonical constructor, accessors, equals, hashCode and toString in a single line, and a compact constructor to validate and normalise.

Java
public record Order(long customerId, long warehouseId, String currency, long discountCents, boolean express) {
public Order { // compact canonical constructor
if (customerId <= 0) throw new IllegalArgumentException("customerId");
currency = Objects.requireNonNullElse(currency, "USD");
if (discountCents < 0) throw new IllegalArgumentException("discount");
}
public static Order forCustomer(long customerId) { // factories still help for common cases
return new Order(customerId, DEFAULT_WAREHOUSE, "USD", 0, false);
}
}

Records do not solve the many-parameters problem by themselves, since the canonical constructor is still positional. They combine well with static factories for common cases, and with a builder when there are many optional fields. Small value types for the arguments, such as a CustomerId record wrapping the long, remove the swapping risk entirely, because the compiler then rejects a WarehouseId where a CustomerId is expected.

5Chaining Everything to One Canonical Constructor

Whichever option we choose, all paths should end in one constructor that takes every field, checks every rule and assigns the fields. Factories call it, the builder's build() calls it, and any remaining convenience constructors delegate to it with this(...). Then there is exactly one place where an Order can become valid, and adding a rule means changing one method.

Java
public Order(long customerId) {
this(customerId, DEFAULT_WAREHOUSE, "USD", 0, false); // delegates, adds no rules of its own
}
private Order(long customerId, long warehouseId, String currency, long discountCents, boolean express) {
if (customerId <= 0) throw new IllegalArgumentException("customerId must be positive");
if (discountCents < 0) throw new IllegalArgumentException("discount must not be negative");
this.customerId = customerId;
this.warehouseId = warehouseId;
this.currency = Objects.requireNonNull(currency);
this.discountCents = discountCents;
this.express = express;
}
Order.forCustomer(-1); // IllegalArgumentException, whichever entry point was used
Choosing an alternative
OptionBest whenMain cost
Static factoriesa few well-known ways to create itstill positional parameters
Buildermany optional parametersextra class, required fields checked at run time
Record + compact constructorplain immutable datacanonical constructor is positional
Value types for argumentssame-typed parameters get swappeda small type per concept
One canonical constructoralways, under any optionnone: it is the foundation

Notice that the convenience constructor only fills in defaults. Because it cannot skip the canonical constructor, an invalid Order is rejected the same way no matter which factory, builder or constructor the caller chose.

6Follow-up questions

Is Lombok's @Builder a good answer?

It removes the boilerplate of writing a builder, which is useful, but it adds an annotation processor to the build and hides the generated code. It also does not validate required fields on its own; we still need checks in the constructor it calls. Many teams accept it, others prefer records plus hand-written factories.

How do you migrate callers away from the six constructors?

Add the factories or builder first, mark the old constructors @Deprecated with a pointer to the replacement, and make each old constructor delegate to the canonical one so behaviour is consistent at once. IDE refactorings or a scripted change can then move callers, and the constructors are removed when no callers remain.

When would you keep multiple constructors?

When there are two or three with clearly different, non-overlapping parameter types, such as a copy constructor and a constructor from all fields. The trouble starts with many constructors and same-typed parameters, not with constructors as such.

7Conclusion

In this answer, we saw that six telescoping constructors make calls hard to read and let same-typed arguments be swapped silently, while validation drifts between constructors. Named static factories make intent clear and can return cached or subtype instances, builders suit many optional parameters at the cost of an extra class and run-time checks of required fields, and records with compact constructors suit plain data, with small value types removing the swapping risk. Under every option, all paths should chain to one canonical constructor so validation lives in exactly one place.

What to say in the interviewAbout 80 seconds aloud

Open with

The core problem with six telescoping constructors is readability and safety: at the call site nobody can tell what new Order(42, 7) means, and when parameters share a type, like several longs, callers can swap them and the compiler won't notice.

Then, if they want more

Also, defaults and validation tend to drift between the constructors. I'd offer three alternatives depending on the class. If there are a few well-known ways to create it, named static factories like Order.forCustomer or Order.expressFrom make intent obvious, and they can return cached instances or subtypes, though their parameters are still positional.

If there are many optional parameters, a builder lets callers name each value; the cost is an extra class and that missing required fields are only caught when build() runs, so I'd put required values in the builder's factory method.

If Order is really plain immutable data, a record with a compact constructor gives one validated constructor plus equals and hashCode for free, and I can still add factories. To stop swapped IDs, small value types like CustomerId help a lot.

Whatever we choose, I'd make every path go through one canonical constructor that does all the validation, so there's exactly one place that defines a valid Order.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A domain class has six constructors with different parameter combinations and callers...": https://scrivio-interview-library.netlify.app/java/classes-and-objects/160e33c83e/