Design Patterns · Junior · Question 10 of 75
When do you need an Adapter?
- ✓Correct answer: When you need to convert someone else's interface into the one your code expects
- 2When you need to speed up a slow function with a cache
- 3When you need to hide an object from unauthorized users
Explanation
Example: the API returns { user_name, created_at }, while the UI expects { name, createdAt: Date }. An adapter function at the boundary transforms the data, and when the API changes only it needs editing. Third-party SDKs are adapted to your own interface the same way.