Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

SOLID was formulated in the 1990s and 2000s for object-oriented codebases. With records, sealed types, lambdas and microservices in modern Java, which parts still matter, which need reinterpretation, and how do you teach them to an organization?

Single responsibility and dependency inversion matter as much as ever, and they now apply at the level of modules and services as well as classes. Open/closed and interface segregation need reinterpretation: we get extension through functions and composition rather than subclassing, sealed types deliberately choose closed variation, and segregation applies to service APIs and events. We teach all of it through trade-offs in our own code and measure coupling with tools instead of arguing about principle names.

Why this question is asked

SOLID is five principles collected in the late 1990s and early 2000s, when Java code meant deep class hierarchies and the main tool for change was a new subclass. Modern Java looks different: records, sealed interfaces, pattern matching, lambdas, and systems split into many services. Senior interviewers ask this to see whether we understand the problems the principles solve, and whether we can lead engineers to apply them with judgement. In this answer, we will recap what each principle says, see which ones carry over unchanged, reinterpret open/closed and interface segregation for modern Java and services, and finish with how to teach and measure all of this across an organization.

1A Quick Recap of the Five Principles

Single responsibility says a unit of code should have one reason to change, meaning one group of people or one kind of requirement that drives its changes. Open/closed says we should be able to add new behaviour without editing code that already works. Liskov substitution says a subtype must keep the promises its supertype makes, so callers never need to know which implementation they hold. Interface segregation says clients should not be forced to depend on methods they do not use. Dependency inversion says high-level policy should depend on abstractions that it owns, and low-level details such as databases and HTTP clients should implement those abstractions.

Notice that none of these principles is really about classes. Each one is about change: who causes it and how far it spreads. That is the lens we will use.

SOLID then and now
PrincipleClassic readingModern reading
Single responsibilityOne reason to change per classSame, at class, module and service level
Open/closedExtend by subclassingExtend by functions, composition, plug-ins
Liskov substitutionSubclasses keep the contractEvery implementation and service version keeps it
Interface segregationSmall Java interfacesSmall APIs, focused events, narrow clients
Dependency inversionDepend on interfacesDomain owns ports; adapters at the edges
The intent of each principle survives; what changes is the scale and the mechanism we use.

2What Still Holds: Single Responsibility and Dependency Inversion

Single responsibility is the most durable of the five because it describes how change arrives. A class that formats invoices and calculates tax changes whenever finance or the design team asks for something. The same reasoning applies one level up. A module that owns both customer profiles and loyalty points will be edited by two teams, and a service that does both will be deployed for two reasons. So the question we ask at every scale is the same: who will ask for changes here, and are they the same people?

Dependency inversion also scales up cleanly. Inside a service, the domain code declares the interface it needs, often called a port, and the infrastructure provides an adapter for it. The reason is that the domain then compiles and tests without the database or the payment provider, and replacing the provider touches only the adapter.

Java
// The domain owns this interface; it says what pricing needs, not how it is fetched
public interface ExchangeRates {
BigDecimal rate(Currency from, Currency to);
}
// Domain policy depends only on the port
public record PriceConverter(ExchangeRates rates) {
Money convert(Money m, Currency to) {
return new Money(m.amount().multiply(rates.rate(m.currency(), to)), to);
}
}
// Infrastructure implements it, in a package the domain never imports
class EcbRatesClient implements ExchangeRates { /* HTTP call, caching, retries */ }

Between services, the same idea becomes a consumer-driven contract: the caller states what it needs, and the provider promises to keep that shape.

3Reinterpreting Open/Closed for Lambdas and Sealed Types

The original open/closed principle was usually taught with an abstract base class and a new subclass per case. In modern Java we rarely need inheritance for that. A rule engine can accept a list of functions, Spring can pick up a new bean that implements an interface, and a strategy can be a lambda. The engine stays closed for modification while the set of rules stays open.

Java
// Open variation: new discount rules are added without touching the engine
List<Function<Order, BigDecimal>> rules = List.of(
o -> o.total().multiply(new BigDecimal("0.05")), // loyalty, 5 percent
o -> o.items().size() > 10 ? new BigDecimal("20") : BigDecimal.ZERO);
// Closed variation, chosen on purpose: the set of payment kinds is fixed
sealed interface Payment permits Card, BankTransfer, Voucher {}
record Card(String last4) implements Payment {}
record BankTransfer(String iban) implements Payment {}
record Voucher(String code) implements Payment {}
static BigDecimal fee(Payment p) {
return switch (p) { // no default: the compiler checks every case
case Card c -> new BigDecimal("0.30");
case BankTransfer b -> BigDecimal.ZERO;
case Voucher v -> BigDecimal.ZERO;
};
}

The sealed interface looks like a violation of open/closed and is not. Data-oriented code deliberately closes the set of variants so that adding an operation is easy: we write a new switch and the compiler reports any missing case. Adding a variant means editing every switch, which is the right trade when variants are stable and operations keep growing, as with events, commands and results. So open/closed becomes a choice: decide which axis of change must be cheap, and make that one open.

4Interface Segregation for Service APIs and Events

Interface segregation was written about Java interfaces, but today its biggest effect is on network APIs and messages. Picture an OrderUpdated event that carries the whole order, 60 fields, published every time anything changes. The shipping service reads three fields, but it still has to deserialize all of them, it breaks when a field it never used is renamed, and it wakes up for changes it does not care about. That is exactly the fat interface problem, only now it crosses team boundaries and deployment schedules.

The fix follows the same reasoning. We publish focused events such as OrderShipped or OrderAddressChanged, offer separate read and write endpoints when clients differ, and give each client only the scopes it needs. Java interfaces still benefit too, but the expensive mistakes are now in contracts between services.

5Teaching the Principles to an Organization

The worst way to teach SOLID is as five rules checked in code review. Engineers then add an interface to every class, split classes until each has one method, and argue about violations, and the codebase gets harder to read.

What works better is teaching each principle as a trade-off, with examples from our own systems. We take a real module that is painful to change, show the commits that touched it, and walk through a refactoring and what it cost: more files and one more hop to read, but changes now stay in one place. Then we review outcomes instead of names. If a package changes every week together with three others, it has a coupling problem whatever we call it; if a class has had one commit in two years, splitting it gains nothing.

6Measuring Coupling Instead of Arguing About It

Tools turn design discussions into facts. Dependency analysis such as jdeps or an IDE dependency matrix shows which packages depend on which. Change coupling from version control shows which files are always committed together. And architecture tests, for example with ArchUnit, turn an agreed rule into a test that fails the build.

Java
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
@AnalyzeClasses(packages = "com.acme.billing")
class ArchitectureTest {
@ArchTest
static final ArchRule domainStaysIndependent =
noClasses().that().resideInAPackage("..domain..")
.should().dependOnClassesThat()
.resideInAnyPackage("..web..", "..persistence..", "org.springframework..");
// fails the build with the offending class and dependency listed
}

This test is dependency inversion written down as a check: the build simply refuses a domain class that imports a repository. Over a few months, the dependency graph and change coupling numbers tell us whether the teaching is working.

7Follow-up questions

Is Liskov substitution still relevant if we avoid inheritance?

Yes, and arguably more than before. Every implementation of an interface, every Spring bean behind a port, and every new version of a service is a substitute for what callers were using. If a new implementation returns empty results where the old one threw an error, callers break even though the types match. Liskov is now mostly about behavioural contracts: errors, nulls, ordering and timing.

How do you stop the principles being used as weapons in code review?

We agree that a review comment must name the concrete cost, such as these two classes always change together, or this test needs a database for no reason, rather than the principle. That keeps the discussion about the code and its history, and it makes it easy to say no when the cost is hypothetical.

8Conclusion

In this answer, we saw that SOLID is about managing change. Single responsibility and dependency inversion carry over and now apply at module and service level, open/closed becomes a deliberate choice between open variation through functions and closed variation through sealed types, and interface segregation matters most for APIs and events. We teach with trade-offs from our own code, and let ArchUnit tests, dependency analysis and change coupling show whether the design improves.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd start by saying that every SOLID principle is about change: who causes it and how far it spreads. Single responsibility and dependency inversion matter as much as ever, at class, module and service level: I ask who will request changes, and I let the domain own ports that adapters implement.

Then, if they want more

Open/closed needs reinterpreting. We rarely subclass to extend anymore; we pass functions, compose strategies or register beans. And sealed interfaces with exhaustive switches deliberately close the set of variants so that adding operations is cheap and the compiler catches missing cases. That's a conscious trade, not a violation.

Interface segregation now matters most for APIs and events: a fat event with sixty fields couples every consumer to every change, so I prefer focused events and narrow endpoints. Liskov becomes about behavioural contracts between implementations and service versions. For teaching, I avoid rules enforced in review, which produce an interface for every class.

I use painful modules from our own codebase, their commit history and a refactoring with its cost, then review outcomes like change frequency and coupling, and put the important rules into ArchUnit tests so nobody argues about principle names.

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 "SOLID was formulated in the 1990s and 2000s for object-oriented codebases. With records...": https://scrivio-interview-library.netlify.app/java/oop-principles/b9084f2841/