← Back to PatternPip

ADAPTER / THE WALKTHROUGH

Keep the display.
Translate the difference.

From a compatible service to an adapter around an existing feed.

CHAPTER 1 OF 3

The display already speaks Celsius.

Celsius Station provides read(), returning a temperature in Celsius and a named condition. The display can use this response directly.

Request weather. Change the sample and see that the same display works.

FOLLOW THE RESPONSE

One service. A shared language.

Try it yourself

These local sample services describe the same weather in different ways. Request a reading and follow the data returning to the app.

THE PROVIDER

Celsius Station

read()
{
  "celsius": 18,
  "condition": "sunny"
}

Sample response · app format

ALREADY COMPATIBLE

No translation needed

Celsius and a named condition already satisfy WeatherSource.

THE APP’S DISPLAY

Weather panel

source.read()

—

Waiting for a reading

Expects Celsius + sunny / rainy.
Display rounds to one decimal.

Request weather to follow the response from provider to display.

Try this: choose another sample. Every reading already has Celsius and a named condition.

Reduced motion is on; results appear immediately.

A compatible service is enough.

Read the familiar service

export function readOriginalPanel(station: CelsiusStation): WeatherReading {
  return station.read();
}

What the app expects

export type WeatherReading = Readonly<{
  celsius: number;
  condition: "sunny" | "rainy";
}>;
export interface WeatherSource {
  read(): WeatherReading;
}

Each chapter starts fresh. Theme and language changes preserve the current example.