Java Structural patterns
Composing objects. This is where Spring's proxies live, so these questions connect directly to framework behaviour.
3 concepts · 8 interview questions
What this topic covers
Every concept in structural patterns, and the questions each one gets asked as. Where a question links, it has a full write-up.
Proxy and decorator
Both wrap an object and implement its interface. A proxy controls access to it; a decorator adds behaviour. The distinction is intent, not structure.
- What is the difference between a proxy and a decorator?
- Where does Spring use the proxy pattern?
- Where does the JDK use decorators?
Adapter and facade
An adapter makes an incompatible interface usable; a facade puts a simple front on a complicated subsystem. Both are about the shape of a boundary.
- Adapter or facade — how do you tell them apart?
- How would you integrate a third-party library you might replace?
- What is an anti-corruption layer?
Composite and flyweight
Composite treats a tree and a leaf the same way; flyweight shares immutable instances to avoid allocating identical objects.
- Where would a composite structure be the right model?
- Where does Java use the flyweight pattern?