🏗️Adapter Pattern
Also known as Adapter, Wrapper Pattern
A wrapper that lets one piece of code fit another.
Think of it like
Think of it like a travel plug. Your charger stays the same, and the plug makes it fit the wall.
Example
Jack's app expects a send method. The new text library has a postText method. A small adapter class turns one into the other.
Why it matters
It lets you use outside code without letting its shape spread through your whole app.
Definition
Common mistake
Key takeaways
- 1Wrap and translate. One shape into another.
- 2Neither side changes. The adapter does the work.
- 3Guard the border. Around outside code.