Design Patterns interview question · Most asked
Compare Adapter, Decorator, Proxy and Facade.
Summary
All four wrap something. Adapter gives an existing object a different interface so it fits; Decorator keeps the same interface and adds behaviour (stackable); Proxy keeps the same interface and controls access (lazy, permissions, remote); Facade offers a new, simpler interface over a whole subsystem.
Longer Answer
The code shape can be nearly identical (a class holding another and delegating), so the distinction is intent:
| Pattern | Interface | Intent |
|---|---|---|
| Adapter | different | make it fit |
| Decorator | same | add behaviour |
| Proxy | same | control access |
| Facade | new, simpler, over many classes | simplify |
Naming the wrapper by its intent tells the next reader why it exists.
Key Points
- Adapter: fit a different interface.
- Decorator: add behaviour, same interface.
- Proxy: control access, same interface.
- Facade: simplify a subsystem.
Deep dive: Design Patterns, Explained Simply: Choosing the Right Pattern
Explanation
What interviewers look for
Intent-based distinctions, not just structure.
Follow-up questions
- Can one class be both a proxy and a decorator?
More most-asked Design Patterns questions
- What problem does the Builder pattern solve? Show an example.
- Explain the SOLID principles.
- What is a design pattern, and why are they useful?
- What is the difference between dependency inversion, dependency injection and inversion of control?
- Why is composition often preferred over inheritance?
- What is dependency injection, and what forms does it take?
- Explain the Factory Method pattern and how it differs from a simple factory.
- How do you implement a Singleton, and why is it often considered an anti-pattern?