Scrivio Interview library
DebuggingFoundations8 min read · updated 12 November 2026

Identify the code smells in this method signature and call, and suggest improvements:

Java
void process(Order o, boolean sendEmail, boolean dryRun, String a, String b, int t);
process(order, true, false, "EU", "x1", 3);

The signature has three smells. The two boolean flags mean the method does several different jobs and make every call unreadable; the long list of parameters with names like a, b and t is easy to get wrong; and plain strings and an int stand in for real concepts such as a region, which is primitive obsession. We fix it by splitting the behaviours into separate methods or passing an options object built with a builder, and by using enums and small value types such as Region.EU with clear names.

Why this question is asked

Signatures like this are everywhere in long-lived services. They start with two parameters, and each new requirement adds one more flag or string until nobody can read a call without opening the method. Interviewers show it because spotting the smells is easy, but explaining why each one is dangerous and which refactoring fits shows real experience. In this answer, we will read the call the way a reviewer would, look at each smell and the bug it invites, and then refactor it step by step into code that explains itself.

1Reading the Call as a Reviewer Would

A code smell is a pattern in code that is not a bug by itself but makes bugs likely and change hard. The best way to find smells is to read the code as someone who did not write it. Here is the call.

Java
void process(Order o, boolean sendEmail, boolean dryRun, String a, String b, int t);
process(order, true, false, "EU", "x1", 3);
// What does true mean? What does false mean?
// Is "EU" a region, a currency zone, a tax area?
// Is "x1" a warehouse, a promo code, a carrier?
// Is 3 a retry count, a priority, a number of days?

Every one of those questions can only be answered by opening the method body. That is the core problem: the call site, where most people read the code, carries no meaning. Suppose that after reading the body we learn that a is the sales region, b is the warehouse code and t is the number of delivery attempts. We will use those meanings in the fixes below.

2Smell 1: Boolean Flag Arguments

A boolean parameter that changes what a method does is called a flag argument. It is a sign that the method really does two or more things and chooses between them at runtime. With two flags, process() has four possible behaviours: real run with email, real run without email, dry run with email (does that even make sense?) and dry run without email.

Flags also make calls unreadable. process(order, true, false, ...) gives no hint which true is which, and swapping them compiles without a warning. Inside the method, flags usually show up as if (dryRun) blocks scattered through the body, which makes it hard to see what each path really does and easy to forget the check in one place, for example sending an email during a dry run.

3Smell 2: A Long Parameter List With Unclear Names

Six parameters is already a lot to hold in our head, and the names a, b and t give us nothing to hold on to. The bigger danger is that three of the parameters share types with others: a and b are both String, and sendEmail and dryRun are both boolean. If a caller writes process(order, true, false, "x1", "EU", 3), the compiler is perfectly happy, and the order is routed to a warehouse called EU in a region called x1.

Long parameter lists also make change painful. Adding a seventh parameter means editing every caller, and callers pass dummy values for parameters they do not care about, which hides which values actually matter.

4Smell 3: Primitive Obsession

Primitive obsession means using basic types like String and int for domain concepts that deserve their own type. A region is not any string; there is a small set of valid regions. A warehouse code has a format. A number of delivery attempts must be positive and probably has a maximum. As plain primitives, none of those rules is enforced, so "eu", "Europe" and "" are all accepted and fail somewhere deep in the code, far from the mistake.

The smells and their refactorings
SmellWhat goes wrongRefactoring
Boolean flagsone method, four behaviours; true/false unreadableseparate methods, or an enum mode
Long parameter listsame-typed arguments can be swapped silentlyparameter object or builder
Unclear names a, b, tmeaning only visible inside the methodrename to region, warehouse, attempts
Primitive obsessioninvalid values accepted, checked lateenum Region, value type WarehouseCode

5Fix 1: Split the Behaviours and Introduce Real Types

We start with the flags. A dry run is a different operation from a real run: it should calculate and validate but not change anything. So it gets its own method. Sending an email is a separate concern that the caller can choose to do after a successful run. Then we replace the primitives with types that carry meaning and validate themselves.

Java
enum Region { EU, US, APAC }
record WarehouseCode(String value) {
WarehouseCode {
if (!value.matches("[A-Z]\\d")) throw new IllegalArgumentException("bad warehouse: " + value);
}
}
record DeliveryAttempts(int value) {
DeliveryAttempts {
if (value < 1 || value > 5) throw new IllegalArgumentException("attempts must be 1-5");
}
}
class OrderFulfilment {
FulfilmentResult fulfil(Order order, Region region, WarehouseCode warehouse, DeliveryAttempts attempts) { ... }
FulfilmentPreview preview(Order order, Region region, WarehouseCode warehouse) { ... } // the old dry run
}
var result = fulfilment.fulfil(order, Region.EU, new WarehouseCode("X1"), new DeliveryAttempts(3));
confirmations.send(order, result); // the old sendEmail = true, now explicit
new WarehouseCode("EU"); // IllegalArgumentException: bad warehouse: EU

Notice what changed. Swapping region and warehouse no longer compiles, because they are different types. An invalid warehouse code fails at the moment it is created, with a clear message, instead of deep in the logic. And the call now reads like a sentence, so nobody needs to open the method to understand it. The email moved out of the method, which also means preview() can never send one by accident.

6Fix 2: An Options Object Built With a Builder

Sometimes we cannot split the method, for example when there really are many optional settings, or when the method is a public API we must keep stable. Then we group the settings into one options object and build it with named steps, so every value is labelled at the call site and optional values have defaults.

Java
record FulfilmentOptions(Region region, WarehouseCode warehouse, DeliveryAttempts attempts,
boolean notifyCustomer, Mode mode) {
enum Mode { LIVE, DRY_RUN }
static Builder builder(Region region, WarehouseCode warehouse) { return new Builder(region, warehouse); }
static final class Builder {
private final Region region; private final WarehouseCode warehouse;
private DeliveryAttempts attempts = new DeliveryAttempts(3); // default
private boolean notifyCustomer = true;
private Mode mode = Mode.LIVE;
Builder(Region r, WarehouseCode w) { region = r; warehouse = w; }
Builder attempts(int n) { attempts = new DeliveryAttempts(n); return this; }
Builder withoutNotification() { notifyCustomer = false; return this; }
Builder dryRun() { mode = Mode.DRY_RUN; return this; }
FulfilmentOptions build() { return new FulfilmentOptions(region, warehouse, attempts, notifyCustomer, mode); }
}
}
fulfilment.fulfil(order, FulfilmentOptions.builder(Region.EU, new WarehouseCode("X1")).attempts(3).build());

The required values go into builder(), so nobody can forget them, and the optional ones have names and defaults. Even the remaining boolean is now set by a method called withoutNotification(), and the dry run is an enum value rather than a bare false. I would still prefer Fix 1 when the behaviours are truly different, because one method with a mode inside often keeps the scattered if blocks we wanted to remove.

7Follow-up questions

Is every boolean parameter a smell?

No. A boolean that is data, such as setActive(boolean active) or a record field, is fine because the method does the same thing either way. The smell is a boolean that selects between different behaviours, especially when the call site shows a bare true or false. If a boolean must stay, an enum with two named values often reads better.

How many parameters are too many?

There is no hard limit, but beyond three or four, and especially when several share a type, calls get hard to read and easy to swap. The question to ask is whether some parameters always travel together, like region and warehouse. If they do, they are probably one concept that deserves a type of its own.

Do value types like WarehouseCode cost performance?

Very little in normal service code. A small record is a short-lived object that the JVM allocates and collects cheaply, and the cost is tiny next to a database or HTTP call. The benefit, errors caught at compile time or at the boundary, is far larger. Value classes from Project Valhalla aim to make such wrappers even cheaper in future JDKs, but we do not need to wait for them.

8Conclusion

In this answer, we read process(order, true, false, "EU", "x1", 3) as a reviewer would and found three smells: boolean flags that hide several behaviours, a long list of vaguely named parameters that can be swapped without a compiler error, and primitives standing in for domain concepts. We split the behaviours into fulfil() and preview(), moved the email out, replaced the strings and the int with Region, WarehouseCode and DeliveryAttempts, and saw an options object with a builder as the alternative when one method must stay.

What to say in the interviewAbout 100 seconds aloud

Open with

The first thing I notice is that the call process(order, true, false, "EU", "x1", 3) cannot be understood without opening the method. That points to three smells. The two booleans are flag arguments: they mean the method does several different things, four combinations in fact, and true and false at the call site are unreadable and easy to swap.

Then, if they want more

Then there is a long parameter list with meaningless names, a, b and t, where two strings sit next to each other, so passing them in the wrong order compiles fine and fails at runtime.

And it is primitive obsession: a region, a warehouse code and what turns out to be a number of delivery attempts are all plain String and int, so invalid values like 'Europe' are accepted and fail late.

My fix would be to split the behaviour first: a fulfil method for the real run and a preview method for the dry run, and the email sent explicitly by the caller after success.

Then I would introduce types: an enum Region with EU, US and APAC, and small records such as WarehouseCode and DeliveryAttempts that validate in their constructors, and rename everything clearly. The call becomes fulfil(order, Region.EU, new WarehouseCode("X1"), new DeliveryAttempts(3)), which reads like a sentence and cannot be swapped.

If the method has to stay as one public entry point with many optional settings, I would pass an options object built with a builder, with required values in the builder method and defaults for the rest.

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 official documentation for the version you use. 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 "Identify the code smells in this method signature and call, and suggest improvements:": https://scrivio-interview-library.netlify.app/java/clean-code/0a4f07c52e/