Scrivio Interview library

Structural patterns

20 questions in 7 subtopics.

Adapter

ConceptFoundations6 min read
Explain the adapter pattern and give examples from the JDK and Spring.
DesignIntermediate7 min read
You must integrate three shipping carriers with different APIs, data models and error codes behind one ShippingGateway interface used by the order domain. Design the adapters and explain how you test them.
ScenarioAdvanced7 min read
You must migrate 150 services from one HTTP client library to another over a year. How can the adapter pattern help, and how do you avoid leaving a permanent extra layer?

Decorator

CodingFoundations6 min read
Write a decorator that adds retry around this interface:
interface PriceService {
Price price(String sku);
}
Then explain why a decorator is better here than a subclass.
DebuggingIntermediate6 min read
A team wraps a client as new MetricsClient(new RetryClient(new CachingClient(realClient))). Dashboards show fewer failures than the remote service reports, and cache hits are counted as very fast remote calls. Explain what the order does and propose a better order.
LeadershipPrincipal6 min read
Over two decades Java moved from hand-written proxies and decorators to frameworks generating them at run time (Spring AOP, bytecode generation), and now toward build-time generation for AOT and native images. What does this mean for how you design cross-cutting concerns in systems expected to live ten or more years?

Proxy

ConceptFoundations6 min read
Spring AOP uses proxies for @Transactional. Explain JDK dynamic proxies versus class-based (CGLIB-style) proxies, and why a @Transactional method called from another method in the same class runs without a transaction.
CodingIntermediate6 min read
Write a JDK dynamic proxy that logs the duration of every call to any interface, and describe the pitfalls.
LeadershipAdvanced7 min read
Remote proxies, such as RMI stubs, EJB remote interfaces and declarative HTTP clients, make a network call look like a local method call. What problems has that caused, and what guidelines would you give teams that use declarative HTTP clients today?
LeadershipPrincipal7 min read
Service meshes moved retries, mutual TLS and routing from in-process libraries into sidecar proxies, and newer designs move some of it into node-level or proxyless modes. How should you decide where cross-cutting network concerns live over a decade?

Facade

ConceptFoundations5 min read
What is the facade pattern, and how does it differ from adapter? Give Java examples.
ScenarioIntermediate6 min read
An OrderFacade class has grown to 3,000 lines and 80 public methods used by many controllers and jobs. Every change causes merge conflicts. What do you do?
DesignAdvanced7 min read
A platform team proposes a company-wide facade library that wraps Kafka, HTTP clients and database access for all services. Evaluate it and describe how you would design it if approved.

Composite

CodingFoundations7 min read
Model pricing eligibility rules where a rule can be a single condition (such as minimum order total) or a group combining other rules with AND or OR. Write the interface and classes using the composite pattern.
DesignIntermediate7 min read
Compare a classic polymorphic composite (each node implements evaluate) with a sealed interface of records plus switch pattern matching for an expression tree in Java 21 and later. When do you choose each?

Bridge

DesignFoundations8 min read
A notifications module has classes OrderEmail, OrderSms, OrderPush, AlertEmail, AlertSms, AlertPush, ReminderEmail and so on. Refactor it with the bridge pattern.
ConceptIntermediate6 min read
Explain the bridge pattern and show how JDBC or SLF4J fits it. How does bridge differ from adapter?

Flyweight

ConceptFoundations7 min read
Explain the flyweight pattern and give JDK examples. What property must flyweight objects have?
ScenarioIntermediate7 min read
A market data service keeps 30 million Trade objects in memory. A heap histogram shows that String objects for the exchange code and currency, with only a few hundred distinct values, use several GB. How would you reduce this?
LeadershipPrincipal7 min read
Memory-saving techniques such as flyweights and interning matter at scale. Over years, how do you decide whether to remove duplication in application code or rely on runtime features such as compact strings, string deduplication and possible future value classes?