0
0
LLDsystem_design~3 mins

Why Adapter pattern in LLD? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could make any device work together without changing a single wire?

The Scenario

Imagine you have two devices that need to connect, like a phone charger and a power outlet, but their plugs don't match.

Manually, you try to force one into the other, causing damage or no power at all.

The Problem

Trying to connect incompatible parts directly is slow and frustrating.

You waste time fixing errors or creating custom solutions for each new device.

This leads to messy, hard-to-maintain systems.

The Solution

The Adapter pattern acts like a plug converter.

It wraps one interface so it looks like another, letting incompatible parts work together smoothly.

This saves time and keeps your system clean and flexible.

Before vs After
Before
if device.type == 'USB-C':
    connect_usb_c(device)
else:
    print('Incompatible device')
After
adapter = DeviceAdapter(device)
adapter.connect()
What It Enables

It enables seamless integration of different systems without changing their core code.

Real Life Example

Using a travel adapter to plug your laptop charger into foreign power outlets with different socket types.

Key Takeaways

Manual connections fail when interfaces differ.

Adapter pattern converts one interface to another.

It promotes reusable and flexible system design.