← Back to PatternPip

ADAPTER / PRACTICE

One player.
Different library languages.

You met Adapter through weather data. Now connect an older audio library to an existing player.

YOUR MISSION / AUDIO LIBRARIES

The music fits.
The interface does not.

Your player calls load(id). The older library only offers findTrack(id), milliseconds and access codes. Connect them without teaching the player vendor-specific rules.

Library speakslength_ms: 185000access_code: "ok"Player expectsdurationSeconds: 185playable: true

Preserve the track’s meaning, not just its field names. Unsupported codes must produce an error, not a guessed permission.

01 / DESIGN THE TRANSLATION

Make three design choices.

Choose who owns the mismatch, then decide how to translate the values. Your choices run in every legacy-library test.

Who should understand the library?

Try your own design first. Hints and retries are unlimited.

02 / REQUEST · TRANSLATE · RETURN

Same track. A different interface.

Local simulation

185000 milliseconds and ok should become 185 seconds and playable = true.

Predict first (optional): What should 185000 ms become?

Request ↓ · Response ↑ · Same track ID throughout

CLIENTPlayersource.load("track-01")Expects a title, seconds and a playable boolean.
Call through TrackSource ↓
TRANSLATION BOUNDARYChoose a translation ownerImplements TrackSource · holds the supplied libraryload(id) → findTrack(id)

Waiting for the library response before translating values.

Call findTrack(id) ↓
EXISTING SERVICE / UNCHANGEDLegacyAudio

No library response reached yet.

0 library calls · waiting for request
Step through, or play and pause. Predictions are optional.

Start a trace to test your selected translation. Correct data alone does not prove an isolated client.

Each test uses a fresh local library. Back replays recorded evidence; it does not call the library again. No audio plays or external service runs. Changing a design choice clears verification.

See the code behind your design TypeScript

03 / EXTEND YOUR DESIGN

Another library wants to connect.

ArchiveAudio exposes fetch(id) and returns name, duration_seconds and can_play. Its values already use seconds and a boolean; its method and field names still do not fit TrackSource.

Connect it while keeping the same player. Which edits are needed?

First pass all three legacy-library cases with the same assembly.

Select the required edits, then start the final trace. Finish it to verify the new adapter.

Select all required edits

Compare with a complete solution

No timer and no attempt limit. Try another assembly, use a hint, or reveal the answer when it helps.