How does Façade differ from Adapter?
Facade and Adapter really are similar: both create a layer between the client and the system, but they solve different problems.
1. Purpose
- Facade simplifies working with an already compatible, but complex, system. → makes the interface simpler.
- Adapter makes incompatible interfaces compatible. → makes the interface fit.
Example:
- A facade hides dozens of classes behind it (
VideoConverterinstead ofCodec,Reader,Mixer). - An adapter fits an old class (
OldPlayer) to a new interface (MediaPlayer).
2. Context of Use
| Situation | What fits |
|---|---|
| Need to reduce API complexity | Facade |
| Need to combine incompatible interfaces | Adapter |
3. Relationship with the System
- Facade works with the internal components of a single system - it is an outer shell around a complex module.
- Adapter connects two different systems that have different interfaces.
4. Changing the Interface
- Facade leaves the subsystems' interfaces unchanged, simply combining them into a simplified entry point.
- Adapter translates one interface into another.
5. Analogy
- Facade is like a hotel reception desk: you don't see the inner workings, you just deal with one staff member.
- Adapter is like a power plug converter: it makes incompatible plugs compatible.
6. Conclusion
| Criterion | Facade | Adapter |
|---|---|---|
| Purpose | Simplify access to the system | Combine different interfaces |
| Changes the interface | No | Yes |
| Application | For your own subsystems | For external or legacy modules |
| Result | Simplicity | Compatibility |
Summary: Facade is about simplifying interaction, Adapter is about compatibility between different interfaces.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.