Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

When should an API accept a standard interface such as Function<Order, Money> and when should it define its own functional interface such as PriceCalculator?

Accept a standard interface such as Function<Order, Money> when the parameter is a generic piece of behaviour, because it works with existing method references, streams and libraries without adapters. Define a named interface such as PriceCalculator when the behaviour is a domain concept: the name documents intent, it can declare checked exceptions and carry default methods, and it makes overloads and stack traces clearer in a large codebase. Mark custom interfaces with @FunctionalInterface, and as a rule use standard types for generic utilities and named types for domain concepts.

Why this question is asked

Every time we design a method that takes behaviour as a parameter, we make this choice, often without noticing. Function<Order, Money> is quick to write and works everywhere, but in a large codebase a signature full of Function and BiFunction types can say very little about what is expected. Interviewers ask this design question to see whether we can weigh interoperability against clarity and pick consistently. In this answer, we will look at what standard interfaces give us, what a named interface gives us, see both in code, cover overloads and stack traces, and end with a simple rule and how the two worlds connect.

1What Standard Interfaces Give Us

The interfaces in java.util.function are known to every Java developer and every library. A method that accepts Function<Order, Money> can be passed any lambda, any method reference with the right shape, or any Function already built elsewhere, including ones composed with andThen. It also plugs straight into streams: orders.stream().map(pricing) works with no adapter.

That makes standard interfaces the right choice for generic utilities: a caching helper that takes a Function<K, V> loader, a retry helper that takes a Supplier<T>, or a mapping utility. The behaviour has no domain meaning beyond its shape, so the shape is all the signature needs to say.

Java
// A generic utility: the shape is the whole meaning
static <K, V> V cached(Map<K, V> cache, K key, Function<? super K, ? extends V> loader) {
return cache.computeIfAbsent(key, loader);
}
Money m = cached(prices, sku, catalog::priceOf); // any method reference fits

2What a Named Interface Gives Us

A named interface turns a shape into a concept. PriceCalculator says more than Function<Order, Money>: it tells the reader what the function is for, it gives the method a meaningful name, price instead of apply, and it gives us a place to write Javadoc about the contract, such as whether the result includes tax.

It can also do things the standard interfaces cannot. Its method can declare a checked exception, for example when pricing may call a remote rate service. It can carry default methods that express domain operations, such as applying a discount. And it can evolve: we can add a default method later without touching existing implementations.

Java
@FunctionalInterface
public interface PriceCalculator {
/** Price of the order before tax, in the order's currency. */
Money price(Order order) throws RateUnavailableException; // a checked exception is allowed
default PriceCalculator withDiscount(Percent discount) {
return order -> price(order).minus(price(order).times(discount));
}
static PriceCalculator fixed(Money amount) { return order -> amount; }
}
PriceCalculator list = order -> order.lines().stream().map(Line::total).reduce(Money.ZERO, Money::add);
PriceCalculator sale = list.withDiscount(Percent.of(10));
System.out.println(sale.price(order)); // 90.00 for an order whose lines total 100.00

Notice the @FunctionalInterface annotation. It is optional, but it makes the compiler reject the interface if someone later adds a second abstract method, which would silently break every lambda that implements it. On a custom interface that other teams use, that check is worth having.

3Overloads and Stack Traces in a Large Codebase

Generic types are erased at run time, and that limits overloading. Two methods that take different Function types have the same erasure, so they cannot both exist in one class. Named interfaces are different types even after erasure, so overloads are possible, although we should still avoid overloading on functional interfaces of the same shape, because lambdas can then become ambiguous.

Java
class Checkout {
void configure(Function<Order, Money> pricing) { }
void configure(Function<Order, Tax> taxes) { }
// error: name clash: both methods have the same erasure configure(Function)
}
class Checkout2 {
void configure(PriceCalculator pricing) { } // fine: distinct types
void configure(TaxRule taxes) { }
// but checkout2.configure(o -> ...) is ambiguous if both have the same shape,
// so better: configurePricing(...) and configureTaxes(...)
}
Standard or named interface
ConcernFunction<Order, Money>PriceCalculator
Works with streams and librariesdirectlyvia a method reference, calc::price
Documents intentshape onlyname, method name, Javadoc
Checked exceptionsnot possiblecan be declared
Domain default methodsonly generic andThen, composewithDiscount and others
Overloadsclash after erasurepossible, but avoid same shapes
Search and stack tracesmixed with every Functionpoints to pricing logic

Readability across a big codebase improves in a similar way. Searching for implementations or usages of PriceCalculator finds exactly the pricing logic, while searching for Function<Order, Money> finds every unrelated function with the same shape. When something fails, the line in the stack trace that invokes the behaviour reads calculator.price(order) rather than pricing.apply(order), and profilers and IDE call hierarchies show the domain name. Those differences seem small, but in a codebase with hundreds of developers they make the code much easier to navigate.

4Choosing, and Connecting the Two Worlds

The rule that holds up best is simple: standard types for generic utilities, named types for domain concepts. A cache loader, a retry supplier or a key extractor is generic, so it takes a standard interface. A pricing rule, an approval policy or a fraud check is a domain concept that the business talks about, so it gets a name. Within one module, we stay consistent so readers know what to expect.

The choice is less permanent than it looks, because method references convert between interfaces of the same shape. A named interface can be passed where a Function is needed with calc::price, and a Function can become a PriceCalculator with fn::apply. So a domain API with named types still plugs into streams and generic libraries at the edges.

Java
PriceCalculator calc = list;
List<Money> prices = orders.stream().map(order -> {
try { return calc.price(order); }
catch (RateUnavailableException e) { throw new IllegalStateException(e); }
}).toList();
Function<Order, Money> fn = order -> Money.of(10);
PriceCalculator adapted = fn::apply; // a Function becomes a PriceCalculator

Notice the first example: because price declares a checked exception, using it inside a stream needs the exception handled, which is the honest cost of that feature. If the method declared no checked exception, map(calc::price) would work directly.

5Follow-up questions

Should a named interface extend Function<Order, Money>?

Usually not. Extending Function makes the interface inherit apply and forces the domain method to be apply, or adds a second abstract method, which breaks the functional interface. It is cleaner to keep the named interface independent and convert with a method reference where needed, or to add a default method such as asFunction() that returns this::price.

Does @FunctionalInterface change how the interface works at run time?

No. It is only a compile-time check that the interface has exactly one abstract method, plus documentation. Any interface with a single abstract method can be the target of a lambda, annotated or not.

When is a standard interface a bad choice even for a utility?

When the parameters are easily confused. A BiFunction<String, String, String> taking a template and a locale lets callers swap the arguments without any compile error. A small named interface, or a parameter object, makes the roles explicit.

6Conclusion

In this answer, we saw that standard interfaces like Function<Order, Money> are best for generic utilities, because they work with method references, streams and libraries without adapters. Named interfaces like PriceCalculator suit domain concepts: they document intent, can declare checked exceptions and domain default methods, allow distinct overloads after erasure, and make searches, stack traces and profiles point at the right logic. We mark custom interfaces with @FunctionalInterface, keep each module consistent, and convert between the two with method references such as calc::price and fn::apply.

What to say in the interviewAbout 90 seconds aloud

Open with

My rule is standard types for generic utilities and named types for domain concepts. Standard interfaces like Function<Order, Money> are known to everyone and work with streams, method references and libraries without adapters, so a cache loader, a retry supplier or a key extractor should take one; the shape is all the signature needs to say.

Then, if they want more

A named interface like PriceCalculator is better when the behaviour is a business concept. The name, a method called price instead of apply, and Javadoc document intent and the contract. Its method can declare a checked exception, like a rate service being unavailable, which the standard interfaces cannot.

It can carry default methods such as withDiscount, and it can evolve later. In a large codebase it also helps with overloads, because two methods taking different Function types clash after erasure while distinct named types do not, though I still avoid overloads on the same shape.

It makes searches, call hierarchies and stack traces point at the pricing logic instead of at every Function in the system. I always mark custom interfaces with @FunctionalInterface so the compiler stops anyone adding a second abstract method.

And the choice is not a trap, because method references convert between them: calc::price where a Function is needed, or fn::apply to make a PriceCalculator.

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 "When should an API accept a standard interface such as Function<Order, Money> and when...": https://scrivio-interview-library.netlify.app/java/lambdas/d12c637a54/