Scrivio Interview library
LeadershipAdvanced7 min read · updated 12 November 2026

Teams in your organization create an interface for every class (OrderService and OrderServiceImpl) by default. Is this good abstraction? What guidance would you give?

Not by default. An interface with a single implementation and no planned variation adds a file and a level of indirection without decoupling anything, and the old technical reasons for it are gone: Spring Boot proxies classes directly and Mockito mocks classes, even final ones, out of the box. My guidance is to introduce interfaces at real boundaries, where there are several implementations, module or team boundaries, or ports to infrastructure, to name them by role rather than with an Impl suffix, and to write that down with examples without forcing teams to delete existing interfaces that are cheap to keep.

Why this question is asked

The OrderService and OrderServiceImpl pair is so common in Java code bases that many developers think it is required. It started for good reasons in the 2000s, when JDK dynamic proxies needed interfaces and mocking libraries could not mock classes, and it stayed as a habit long after those reasons disappeared. Interviewers ask this leadership question to see whether we can separate a principle, depend on abstractions where variation is real, from a ritual, and whether we can change a team habit without a pointless rewrite. In this answer, we will look at what the pattern costs, check whether the old reasons still hold, define where interfaces do pay off, talk about naming, and set guidance for the organization.

1What the Default Interface Costs

Picture a service with fifty such pairs. Each has two files where one would do, and every change to a method signature is made twice. Navigating from a caller to the code it calls in an IDE lands on the interface, so developers learn to press 'go to implementation' every time. Javadoc is either duplicated or missing from one of the files. None of that is dramatic on its own, but it is paid on every change, forever.

Java
public interface OrderService { // the only implementation is below
Order place(PlaceOrder cmd);
}
@Service
public class OrderServiceImpl implements OrderService { // the name says nothing about how it differs
public Order place(PlaceOrder cmd) { /* ... */ }
}
@RestController
class OrderController {
private final OrderService orders; // depends on the interface, but there is no choice to make
OrderController(OrderService orders) { this.orders = orders; }
}

Notice what the interface buys here: nothing. There is one implementation, there is no plan for a second, and the interface lives in the same package and module as its implementation, owned by the same team. If the class changes, the interface changes with it. Decoupling means one side can change without the other; here both sides always change together, so nothing is decoupled. The Impl suffix gives it away: when the best name we can find for the implementation is the interface's name plus Impl, there is no second concept to name.

2The Old Reasons No Longer Apply

The first historical reason was proxies. Spring adds transactions, security and caching by wrapping beans in a proxy, a generated object that intercepts calls. Early Spring used JDK dynamic proxies, which can only implement interfaces, so a bean without an interface could not be proxied easily. Spring has supported class-based proxies through CGLIB, which generates a subclass at runtime, for a long time, and Spring Boot has made class-based proxying the default since Boot 2.0 (the spring.aop.proxy-target-class property defaults to true). The only requirement is that the class and its proxied methods are not final.

The second reason was testing. Older mocking libraries could only mock interfaces. Mockito has been able to mock classes for many years, and since Mockito 5 the inline mock maker is the default, so it can mock final classes and methods as well. Spring's own test support, @MockitoBean in recent versions, works with classes. So neither the framework nor the tests need the interface.

Java
@Service
public class OrderService { // no interface
@Transactional
public Order place(PlaceOrder cmd) { /* ... */ } // proxied with a CGLIB subclass in Spring Boot
}
@Test
void controllerReturns201() {
OrderService orders = mock(OrderService.class); // Mockito mocks the class directly
when(orders.place(any())).thenReturn(new Order(42));
// ... call the controller, assert the status is 201
}

3Where Interfaces Do Pay Off

Interfaces earn their cost at real boundaries, places where variation exists or where we want one side to change without the other. The first is multiple implementations, today or clearly planned: a PaymentGateway with Stripe and Adyen implementations, or a NotificationChannel with email, SMS and push. The second is a module or team boundary: when the billing team publishes an API that the orders team consumes, an interface in a small api module lets billing change its internals and release independently. The third is a port to infrastructure, in the hexagonal architecture sense: the domain declares an interface it needs, such as OrderRepository or ExchangeRates, and an adapter implements it with JPA or an HTTP client. Here the interface is owned by the domain, and its point is to keep infrastructure details out of the domain code.

A quick test for any proposed interface is to ask what would vary behind it and who would benefit if it did. If the honest answer is nothing and nobody, the class is enough. Adding the interface later, when a second implementation appears, takes a few minutes with any IDE's extract interface refactoring, so waiting costs very little.

Step throughDoes this class need an interface?
  1. Two or more implementations now or clearly planned?
    YesAdd an interfaceNoCheck boundaries
  2. Crosses a module or team boundary?
    YesAdd an interface in the API moduleNoCheck infrastructure
  3. Is it a port to infrastructure the domain needs?repository, external API, clock
    YesDomain-owned interfaceNoUse the class directly
  4. Use the class directlyextract an interface later if variation appears

4 steps in order. Play them, or step through them one at a time.

4Naming Abstractions by Role

When an interface is justified, its name should describe the role it plays for callers, and each implementation's name should say how it differs. PaymentGateway with StripePaymentGateway and AdyenPaymentGateway reads well: the interface is the concept, the classes are the variants. ExchangeRates with EcbExchangeRates and FixedExchangeRates for tests works the same way. An Impl suffix, or an I prefix on the interface, is a sign that there is only one real concept, and it is worth asking whether the interface is needed at all.

5Writing the Guidance and Rolling It Out

I would write a one-page guideline with examples from our own code: here is a port with two adapters, keep it; here is a service with one implementation in the same package, do not add an interface for new code like this. The rule is simple: new code uses concrete classes by default and introduces interfaces at real boundaries, named by role. Reviewers can point to the page instead of debating taste.

Equally important is what the guidance does not do. It does not ask teams to remove existing interfaces. Deleting hundreds of working interfaces is churn with risk and no customer value, and an interface that already exists costs little to keep. Teams may collapse a pair when they are already changing that code heavily, but nobody funds a project for it. Over a year, new code shows the new style, old code fades as it is rewritten for real reasons, and the debate ends without a fight.

6Follow-up questions

Doesn't depending on a concrete class violate dependency inversion?

Dependency inversion says high-level policy should not depend on low-level details; both should depend on abstractions owned by the policy. An OrderController depending on an OrderService in the same application layer is not a high-level module depending on a detail, they are peers. The principle applies at boundaries such as the domain depending on a repository, which is exactly where the guidance keeps interfaces.

What if a team says the interface makes the design clearer?

Then the interface should express something the class does not, such as a narrow role used by some callers, for example a read-only OrderQueries view of a larger service. That is interface segregation, and it is a good reason. If the interface is just a copy of every public method of its only implementation, it adds no information.

7Conclusion

In this answer, we saw that an interface for every class, with a single implementation and no planned variation, adds files and indirection without decoupling anything, and that the historical reasons, JDK proxies and interface-only mocking, are gone now that Spring Boot uses class-based proxies and Mockito mocks classes by default. Interfaces belong at real boundaries: several implementations, module or team boundaries and ports to infrastructure, named by role rather than with Impl. The guidance is written down with our own examples and applied to new code without forcing anyone to remove interfaces that are cheap to keep.

What to say in the interviewAbout 90 seconds aloud

Open with

No, not as a default. An interface that has exactly one implementation, lives in the same package and is owned by the same team does not decouple anything; both files always change together, and we pay for it with extra files, duplicated signatures and an extra click every time we navigate.

Then, if they want more

The habit came from real constraints that are gone. Spring used JDK dynamic proxies, which need interfaces, but Spring Boot has defaulted to class-based CGLIB proxies since 2.0, and old mocking libraries needed interfaces, while Mockito mocks classes, and with the inline mock maker, the default since Mockito 5, even final ones.

So my guidance would be: write concrete classes by default and introduce an interface at a real boundary. That means multiple implementations, now or clearly planned, like a PaymentGateway with Stripe and Adyen; a module or team boundary where someone else consumes the API; or a port to infrastructure that the domain owns, like a repository or an exchange-rate client.

Name interfaces by their role, and implementations by how they differ, not with an Impl suffix. I would write this down on one page with examples from our own code, apply it in reviews for new code, and explicitly not ask teams to delete existing interfaces, because removing working code that costs little to keep is churn with no value.

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 "Teams in your organization create an interface for every class (OrderService and...": https://scrivio-interview-library.netlify.app/java/oop-principles/399b8bac3f/