DevPrep

All topics › Design patterns

Adapter and Facade: how do you isolate a third-party SDK?

Middle PRO

The gist

An Adapter converts the interface of someone else's class into the one your code expects. You declare a protocol in your domain's terms, and the adapter translates calls into the SDK's API: event names, parameter types, callbacks into async. A Facade solves a different problem — it simplifies a subsystem: one object with a couple of methods hides the orchestration of several classes, the call order and the configuration. A wrapper around a third-party SDK usually plays both roles.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store