# Bridge: Any Control, Any Device

Three ways to control the house (the phone app, voice and the wall panel) times three brands of device made nine classes, and every new control or brand adds a whole row of them; a bridge splits the two into separate families, controls that have a device, so a new control or a new brand is one new class.

Journeyman · OOP · Updated November 17, 2026

By Gregor Dzierzon

## After this lesson you can

- Split two things that change on their own into two families joined by a has-a link, instead of a class for every pair
- Spot the smells that point to Bridge: class names that are pairs, growing as rows times columns

## Key takeaways

- The smell: class names that are pairs (PhoneLumo, VoiceBolt), whose number grows as rows times columns.
- The cause: two things that change on their own, how you control a device and which device it is, are welded into one class.
- The fix: two families, joined by a has-a link. A control holds a device and asks it to act; either side can grow without the other.
- Adapter fits two things together after the fact; Bridge is planned up front, so two sides can change on their own.

**Before this:** *Prefer Composition to Inheritance* (has-a instead of is-a), and *Adapter*, which made each brand fit the hub's own promises.

Maya can control the house three ways: the **phone app**, her **voice**, and the **wall panel** in the kitchen. The first version of the controls was written fast, with one class for each control and each brand of device: the phone app with a Lumo light, voice with a Bolt lock, and so on. Now a smartwatch app is planned, and a fourth brand is on the way. Before either arrives, count the classes. By the end of this lesson you'll have met a pattern for two things that change on their own, called *Bridge*.

## The symptom: a class for every pair

Each control does its own thing first (the phone app shows what was tapped, voice repeats what it heard, the wall panel lights its button), and then the device acts in its brand's way. For the devices, "on" means each one's main job: the light lights, the lock locks, the speaker plays the news.

```csharp
new PhoneLumo().On();
new VoiceBolt().On();
new PanelTuneo().On();

// One class for every control and every brand: three controls times three brands.
class PhoneLumo { public void On() { Console.WriteLine("Phone app: tapped \"kitchen light\""); Console.WriteLine("Lumo [kitchen]: power on"); } }
class PhoneBolt { public void On() { Console.WriteLine("Phone app: tapped \"front door\""); Console.WriteLine("Bolt [front door]: ENGAGED"); } }
class PhoneTuneo { public void On() { Console.WriteLine("Phone app: tapped \"kitchen speaker\""); Console.WriteLine("Tuneo [kitchen]: streaming https://tuneo.example/news"); } }
class VoiceLumo { public void On() { Console.WriteLine("Voice: heard \"kitchen light\""); Console.WriteLine("Lumo [kitchen]: power on"); } }
class VoiceBolt { public void On() { Console.WriteLine("Voice: heard \"front door\""); Console.WriteLine("Bolt [front door]: ENGAGED"); } }
class VoiceTuneo { public void On() { Console.WriteLine("Voice: heard \"kitchen speaker\""); Console.WriteLine("Tuneo [kitchen]: streaming https://tuneo.example/news"); } }
class PanelLumo { public void On() { Console.WriteLine("Wall panel: pressed \"kitchen light\""); Console.WriteLine("Lumo [kitchen]: power on"); } }
class PanelBolt { public void On() { Console.WriteLine("Wall panel: pressed \"front door\""); Console.WriteLine("Bolt [front door]: ENGAGED"); } }
class PanelTuneo { public void On() { Console.WriteLine("Wall panel: pressed \"kitchen speaker\""); Console.WriteLine("Tuneo [kitchen]: streaming https://tuneo.example/news"); } }
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```java
// One class for every control and every brand: three controls times three brands.
class PhoneLumo { void on() { IO.println("Phone app: tapped \"kitchen light\""); IO.println("Lumo [kitchen]: power on"); } }
class PhoneBolt { void on() { IO.println("Phone app: tapped \"front door\""); IO.println("Bolt [front door]: ENGAGED"); } }
class PhoneTuneo { void on() { IO.println("Phone app: tapped \"kitchen speaker\""); IO.println("Tuneo [kitchen]: streaming https://tuneo.example/news"); } }
class VoiceLumo { void on() { IO.println("Voice: heard \"kitchen light\""); IO.println("Lumo [kitchen]: power on"); } }
class VoiceBolt { void on() { IO.println("Voice: heard \"front door\""); IO.println("Bolt [front door]: ENGAGED"); } }
class VoiceTuneo { void on() { IO.println("Voice: heard \"kitchen speaker\""); IO.println("Tuneo [kitchen]: streaming https://tuneo.example/news"); } }
class PanelLumo { void on() { IO.println("Wall panel: pressed \"kitchen light\""); IO.println("Lumo [kitchen]: power on"); } }
class PanelBolt { void on() { IO.println("Wall panel: pressed \"front door\""); IO.println("Bolt [front door]: ENGAGED"); } }
class PanelTuneo { void on() { IO.println("Wall panel: pressed \"kitchen speaker\""); IO.println("Tuneo [kitchen]: streaming https://tuneo.example/news"); } }

void main() {
    new PhoneLumo().on();
    new VoiceBolt().on();
    new PanelTuneo().on();
}
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```python
NEWS = "https://tuneo.example/news"


# One class for every control and every brand: three controls times three brands.
class PhoneLumo:
    def on(self): print('Phone app: tapped "kitchen light"'); print("Lumo [kitchen]: power on")


class PhoneBolt:
    def on(self): print('Phone app: tapped "front door"'); print("Bolt [front door]: ENGAGED")


class PhoneTuneo:
    def on(self): print('Phone app: tapped "kitchen speaker"'); print(f"Tuneo [kitchen]: streaming {NEWS}")


class VoiceLumo:
    def on(self): print('Voice: heard "kitchen light"'); print("Lumo [kitchen]: power on")


class VoiceBolt:
    def on(self): print('Voice: heard "front door"'); print("Bolt [front door]: ENGAGED")


class VoiceTuneo:
    def on(self): print('Voice: heard "kitchen speaker"'); print(f"Tuneo [kitchen]: streaming {NEWS}")


class PanelLumo:
    def on(self): print('Wall panel: pressed "kitchen light"'); print("Lumo [kitchen]: power on")


class PanelBolt:
    def on(self): print('Wall panel: pressed "front door"'); print("Bolt [front door]: ENGAGED")


class PanelTuneo:
    def on(self): print('Wall panel: pressed "kitchen speaker"'); print(f"Tuneo [kitchen]: streaming {NEWS}")


PhoneLumo().on()
VoiceBolt().on()
PanelTuneo().on()
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```javascript
const NEWS = "https://tuneo.example/news";

// One class for every control and every brand: three controls times three brands.
class PhoneLumo { on() { console.log('Phone app: tapped "kitchen light"'); console.log("Lumo [kitchen]: power on"); } }
class PhoneBolt { on() { console.log('Phone app: tapped "front door"'); console.log("Bolt [front door]: ENGAGED"); } }
class PhoneTuneo { on() { console.log('Phone app: tapped "kitchen speaker"'); console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }
class VoiceLumo { on() { console.log('Voice: heard "kitchen light"'); console.log("Lumo [kitchen]: power on"); } }
class VoiceBolt { on() { console.log('Voice: heard "front door"'); console.log("Bolt [front door]: ENGAGED"); } }
class VoiceTuneo { on() { console.log('Voice: heard "kitchen speaker"'); console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }
class PanelLumo { on() { console.log('Wall panel: pressed "kitchen light"'); console.log("Lumo [kitchen]: power on"); } }
class PanelBolt { on() { console.log('Wall panel: pressed "front door"'); console.log("Bolt [front door]: ENGAGED"); } }
class PanelTuneo { on() { console.log('Wall panel: pressed "kitchen speaker"'); console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }

new PhoneLumo().on();
new VoiceBolt().on();
new PanelTuneo().on();
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```typescript
const NEWS = "https://tuneo.example/news";

// One class for every control and every brand: three controls times three brands.
class PhoneLumo { on(): void { console.log('Phone app: tapped "kitchen light"'); console.log("Lumo [kitchen]: power on"); } }
class PhoneBolt { on(): void { console.log('Phone app: tapped "front door"'); console.log("Bolt [front door]: ENGAGED"); } }
class PhoneTuneo { on(): void { console.log('Phone app: tapped "kitchen speaker"'); console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }
class VoiceLumo { on(): void { console.log('Voice: heard "kitchen light"'); console.log("Lumo [kitchen]: power on"); } }
class VoiceBolt { on(): void { console.log('Voice: heard "front door"'); console.log("Bolt [front door]: ENGAGED"); } }
class VoiceTuneo { on(): void { console.log('Voice: heard "kitchen speaker"'); console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }
class PanelLumo { on(): void { console.log('Wall panel: pressed "kitchen light"'); console.log("Lumo [kitchen]: power on"); } }
class PanelBolt { on(): void { console.log('Wall panel: pressed "front door"'); console.log("Bolt [front door]: ENGAGED"); } }
class PanelTuneo { on(): void { console.log('Wall panel: pressed "kitchen speaker"'); console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }

new PhoneLumo().on();
new VoiceBolt().on();
new PanelTuneo().on();
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

Nine classes, and every one of them is two copied lines: one from a control, one from a brand. Now do the sums. The smartwatch app adds a whole row: three more classes. The fourth brand adds a whole column: four more. Both together make sixteen. When the phone app changes how it shows a tap, four classes change; when Bolt changes how it locks, four more.

- **The symptom:** class names that are pairs (`PhoneLumo`, `VoiceBolt`), whose number grows as rows times columns.
- **The cause:** two things that change on their own, *how you control it* and *which device it is*, are welded into one class. Every combination needs its own.

![Rows times columns against rows plus columns: a grid of nine pair classes, three controls (phone app, voice, wall panel) by three brands (Lumo, Bolt, Tuneo), "3 × 3 = 9"; beside it, the controls and the brands as two families joined by one "has a" arrow, "3 + 3 = 6"](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/ee2f9d9106e54209af99d30784716953.webp)

## What would you try?

**One class per control, with an `if` per brand inside.** Three classes instead of nine. But each control now has a brand `if` chain, and the fourth brand edits all three, and the smartwatch copies the chain a fourth time.

**One class per brand, with an `if` per control inside.** The same trade, turned around: the smartwatch edits every brand's class.

**A family tree: `Control`, then `PhoneControl`, then `PhoneLumo` below it.** Inheritance shares the phone app's line, which helps. But the leaves are still pairs, and there are still nine of them.

Every one of these keeps the two things in one class family. What we want is for each to be its own family, so a new control doesn't care about brands, and a new brand doesn't care about controls.

## The fix: a control that has a device

A light switch on the wall doesn't care which bulb is in the lamp, and the bulb doesn't care which switch turns it on. The wire between them is all they share. Swap the switch for a dimmer, or the bulb for a brighter one, and nothing else changes.

![Three different wall switches in a column on the left, a toggle switch, a push button and a dimmer, and three different bulbs in a column on the right, a round bulb, a long tube and a small spotlight, with wires drawn so that any switch could connect to any bulb](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/983dea3ccbba441894419a3b6d925f3b.webp)

In code, the wire is a **has-a** link. Each control holds a device and asks it to act; it never knows the brand. Each device knows its brand's way of acting, and never knows which control asked. That link between two families is called a **bridge**:

![Bridge's roles: two fenced families joined by one "has a" link. Left, what changes in how you control it: the phone app, voice and the wall panel. Right, what changes in which device: the Lumo light, Bolt lock and Tuneo speaker. A control asks its device on()](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/78d0492403394b6da0f59a59a881f320.webp)

```csharp
new PhoneApp(new LumoDevice()).On();
new Voice(new BoltDevice()).On();
new WallPanel(new TuneoDevice()).On();

// One family: the devices. Each knows its brand's way, and nothing about controls.
interface IDevice
{
    string Name { get; }
    void On();
}

class LumoDevice : IDevice { public string Name => "kitchen light"; public void On() => Console.WriteLine("Lumo [kitchen]: power on"); }
class BoltDevice : IDevice { public string Name => "front door"; public void On() => Console.WriteLine("Bolt [front door]: ENGAGED"); }
class TuneoDevice : IDevice { public string Name => "kitchen speaker"; public void On() => Console.WriteLine("Tuneo [kitchen]: streaming https://tuneo.example/news"); }

// The other family: the controls. Each one has a device: that link is the bridge.
abstract class Control
{
    protected readonly IDevice device;
    protected Control(IDevice device) { this.device = device; }
    public abstract void On();
}

class PhoneApp : Control
{
    public PhoneApp(IDevice device) : base(device) { }
    public override void On() { Console.WriteLine($"Phone app: tapped \"{device.Name}\""); device.On(); }
}

class Voice : Control
{
    public Voice(IDevice device) : base(device) { }
    public override void On() { Console.WriteLine($"Voice: heard \"{device.Name}\""); device.On(); }
}

class WallPanel : Control
{
    public WallPanel(IDevice device) : base(device) { }
    public override void On() { Console.WriteLine($"Wall panel: pressed \"{device.Name}\""); device.On(); }
}
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```java
// One family: the devices. Each knows its brand's way, and nothing about controls.
interface Device {
    String name();
    void on();
}

class LumoDevice implements Device { public String name() { return "kitchen light"; } public void on() { IO.println("Lumo [kitchen]: power on"); } }
class BoltDevice implements Device { public String name() { return "front door"; } public void on() { IO.println("Bolt [front door]: ENGAGED"); } }
class TuneoDevice implements Device { public String name() { return "kitchen speaker"; } public void on() { IO.println("Tuneo [kitchen]: streaming https://tuneo.example/news"); } }

// The other family: the controls. Each one has a device: that link is the bridge.
abstract class Control {
    protected final Device device;
    Control(Device device) { this.device = device; }
    abstract void on();
}

class PhoneApp extends Control {
    PhoneApp(Device device) { super(device); }
    void on() { IO.println("Phone app: tapped \"" + device.name() + "\""); device.on(); }
}

class Voice extends Control {
    Voice(Device device) { super(device); }
    void on() { IO.println("Voice: heard \"" + device.name() + "\""); device.on(); }
}

class WallPanel extends Control {
    WallPanel(Device device) { super(device); }
    void on() { IO.println("Wall panel: pressed \"" + device.name() + "\""); device.on(); }
}

void main() {
    new PhoneApp(new LumoDevice()).on();
    new Voice(new BoltDevice()).on();
    new WallPanel(new TuneoDevice()).on();
}
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```python
NEWS = "https://tuneo.example/news"


# One family: the devices. Each knows its brand's way, and nothing about controls.
class LumoDevice:
    name = "kitchen light"
    def on(self): print("Lumo [kitchen]: power on")


class BoltDevice:
    name = "front door"
    def on(self): print("Bolt [front door]: ENGAGED")


class TuneoDevice:
    name = "kitchen speaker"
    def on(self): print(f"Tuneo [kitchen]: streaming {NEWS}")


# The other family: the controls. Each one has a device: that link is the bridge.
class Control:
    def __init__(self, device):
        self.device = device


class PhoneApp(Control):
    def on(self):
        print(f'Phone app: tapped "{self.device.name}"')
        self.device.on()


class Voice(Control):
    def on(self):
        print(f'Voice: heard "{self.device.name}"')
        self.device.on()


class WallPanel(Control):
    def on(self):
        print(f'Wall panel: pressed "{self.device.name}"')
        self.device.on()


PhoneApp(LumoDevice()).on()
Voice(BoltDevice()).on()
WallPanel(TuneoDevice()).on()
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```javascript
const NEWS = "https://tuneo.example/news";

// One family: the devices. Each knows its brand's way, and nothing about controls.
class LumoDevice { name = "kitchen light"; on() { console.log("Lumo [kitchen]: power on"); } }
class BoltDevice { name = "front door"; on() { console.log("Bolt [front door]: ENGAGED"); } }
class TuneoDevice { name = "kitchen speaker"; on() { console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }

// The other family: the controls. Each one has a device: that link is the bridge.
class Control {
  constructor(device) {
    this.device = device;
  }
}

class PhoneApp extends Control {
  on() { console.log(`Phone app: tapped "${this.device.name}"`); this.device.on(); }
}

class Voice extends Control {
  on() { console.log(`Voice: heard "${this.device.name}"`); this.device.on(); }
}

class WallPanel extends Control {
  on() { console.log(`Wall panel: pressed "${this.device.name}"`); this.device.on(); }
}

new PhoneApp(new LumoDevice()).on();
new Voice(new BoltDevice()).on();
new WallPanel(new TuneoDevice()).on();
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

```typescript
const NEWS = "https://tuneo.example/news";

// One family: the devices. Each knows its brand's way, and nothing about controls.
interface Device {
  readonly name: string;
  on(): void;
}

class LumoDevice implements Device { readonly name = "kitchen light"; on(): void { console.log("Lumo [kitchen]: power on"); } }
class BoltDevice implements Device { readonly name = "front door"; on(): void { console.log("Bolt [front door]: ENGAGED"); } }
class TuneoDevice implements Device { readonly name = "kitchen speaker"; on(): void { console.log(`Tuneo [kitchen]: streaming ${NEWS}`); } }

// The other family: the controls. Each one has a device: that link is the bridge.
abstract class Control {
  protected readonly device: Device;
  constructor(device: Device) { this.device = device; }
  abstract on(): void;
}

class PhoneApp extends Control {
  on(): void { console.log(`Phone app: tapped "${this.device.name}"`); this.device.on(); }
}

class Voice extends Control {
  on(): void { console.log(`Voice: heard "${this.device.name}"`); this.device.on(); }
}

class WallPanel extends Control {
  on(): void { console.log(`Wall panel: pressed "${this.device.name}"`); this.device.on(); }
}

new PhoneApp(new LumoDevice()).on();
new Voice(new BoltDevice()).on();
new WallPanel(new TuneoDevice()).on();
```

```text
Phone app: tapped "kitchen light"
Lumo [kitchen]: power on
Voice: heard "front door"
Bolt [front door]: ENGAGED
Wall panel: pressed "kitchen speaker"
Tuneo [kitchen]: streaming https://tuneo.example/news
```

The same six lines, from six classes instead of nine. Any control works with any device: `new Voice(new LumoDevice())` needs no new class. The smartwatch is one new control; the fourth brand is one new device. Both together: eight classes, not sixteen. And the phone app's way of showing a tap is written once, in `PhoneApp`.

In the hub, each device class here would be one of the brand's adapters from *Adapter*, and the controls would ask the hub's front door. This lesson shows only the two families, so the split stands out.

**Where the languages differ.** C#, Java and TypeScript mark `Control` as `abstract`: a class you can't make on its own, only through its subclasses. Python and JavaScript have no such keyword here; `Control` is a plain base class that holds the device.

## How it got its name

The has-a link spans the gap between two families, so the 1994 book named it a **bridge**: the **Bridge pattern**. The book calls the controls' side the *abstraction* and the devices' side the *implementation*. Those are the book's words for "the part people use" and "the part that does the work"; here "implementation" doesn't mean "code" in general. It's Module 1's *prefer composition to inheritance*, applied to two families at once.

Bridge looks a lot like **Adapter**: an object holding another object. The difference is when and why. An adapter is added *after the fact*, to fit something that was never designed to fit. A bridge is planned *up front*, because you can already see two sides that will each keep growing.

## Where you've already used it

- Logging: your code calls one logging interface (`ILogger` in .NET, SLF4J in Java, Python's `logging`), and separate *handlers* or *providers* write to the console, a file or a cloud service. Any kind of log message, through any handler.
- Database code in Java and .NET talks to one set of interfaces, and each database maker's *driver* is the other side of the bridge.
- A game drawn through different graphics systems on different computers: the game's objects on one side, the drawing code on the other.

## When not to use it

- **When only one side varies.** Three controls and one kind of device is plain polymorphism: three classes, no bridge.
- **When the pairs are few and fixed.** Two controls and two devices that will never grow read fine as two classes each.
- **When you're guessing.** Splitting into two families before there's a second member on either side is pattern fever. Wait until a second control or a second device shows up.

The cost is two class families to learn instead of one, and a hop from the control to its device.

**How often you'll meet it:** now and then (our estimate: you'll see it most inside frameworks and drivers, and write one when two kinds of change meet in one class).

## Check yourself

2 questions to try on the lesson page.

## So what

When class names start being pairs, two things that change on their own are stuck in one class. Give each its own family and join them with a has-a link, and both sides can grow one class at a time.

## Key terms

- [Bridge Pattern](https://www.ask-codey.com/glossary/bridge-pattern)
- [Composition over Inheritance](https://www.ask-codey.com/glossary/composition-over-inheritance)
- [Composition](https://www.ask-codey.com/glossary/composition-oop)

## Cheat sheets

- [Bridge: Any Control, Any Device](https://www.ask-codey.com/cheat-sheets/dp-bridge-cheat-sheet)

Source: https://www.ask-codey.com/lessons/dp-bridge
