Skip to content
Ameen Abozaid
In reviewJNR-005-L05

Adapter

  • Lesson 5 of 10
  • 11 min read
  • Junior
On This Lesson 4 topics

The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.

In this lesson

make a foreign interface fit yours.

Planned topics

  • Problem: a third-party API has a different shape from what your code expects.
  • Like a travel plug adapter: it changes the shape, not the power.
  • Your code depends on your interface; the adapter translates the calls.
  • It protects your core from outside changes.
  • JDK example: Arrays.asList, InputStreamReader.
Draft outline details

Demonstration

java
interface CurrencyRates { Money convert(Money m, String to); }
class VendorRatesAdapter implements CurrencyRates {
    private final VendorApi api;
    ...
}

Check your understanding

What does an Adapter change?

Show answer

The shape of an interface, not what it does.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.