← Back to PatternPipCHAPTER 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 yourselfThese 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.
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.