1. Home
  2. Explore
  3. Computer Science
  4. Adapter Design Pattern

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Adapter Design Pattern

Speaker 1Speaker 2

Adapter Design Pattern

1:45
0:00-1:45
  1. Maria

    Alright, today we’re diving into the adapter design pattern. You might have heard it also called a wrapper, and that name gives you a big hint about what it does.

  2. Michael

    A wrapper — so it wraps something up. But before we get into details, let’s quickly place it among those other three patterns that get confused with it: facade, proxy, and decorator. We already covered decorator, so adapter is next.

  3. Maria

    Right. And the key idea for adapter is simple: it makes two incompatible interfaces compatible. Imagine you have a client that expects a certain interface, but you have a class with a completely different one. The adapter sits in between, translating calls so they can work together.

  4. Michael

    So it’s like a travel adapter for your electronics. You plug a US plug into the adapter, and the adapter fits into a European socket. The adapter just converts the shape, not the electricity. Same concept here.

  5. Maria

    Exactly. Let’s do a software example. Say your system has a `ReportGenerator` interface with a method `generateReport()`. But you just bought a third-party library that has a class `FancyReporter` with a method `createFancyDocument()`. Without changing either side, you write an adapter class that implements `generateReport()` and internally calls `createFancyDocument()`. Now they work together seamlessly.

  6. Michael

    That’s the wrapper aspect — the adapter wraps the third-party object and presents the expected interface. And this pattern is especially useful when you’re integrating legacy code or external libraries that you can’t modify.

  7. Maria

    Yes. And that’s the core of the adapter pattern: make things work together without rewriting them. In the next video we’ll talk about the facade pattern, which sounds similar but has a different goal.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent