QA
Beginner LevelSoftware Engineering Principles

What is the Adapter Pattern and how does it bridge incompatible interfaces?

❓ Interview Prompt: Explain the Adapter Structural Pattern, wrapping legacy or third-party APIs, and converting incompatible interface contracts.

The Adapter Pattern acts as a wrapper between two incompatible interfaces, enabling classes to work together that otherwise couldn't due to incompatible API contracts:

Practical Example:

Adapting a third-party analytics API ('logEvent(name, payload)') to match your application's internal logging interface ('writeLog(msg)').

Code Implementation Example

typescript
// Legacy API
class LegacyPrinter { printOld(text: string) { console.log('Legacy:', text); } }

// Target Interface expected by client
interface ModernPrinter { print(text: string): void; }

// Adapter
class PrinterAdapter implements ModernPrinter {
  constructor(private legacy: LegacyPrinter) {}
  print(text: string) { this.legacy.printOld(text); }
}
💡Bridging incompatible interfaces with the Adapter pattern.
🎯 Interview Key Takeaway

Use the Adapter pattern to wrap incompatible third-party or legacy APIs into your application's expected interface.

#Adapter#Design Patterns#Structural#Beginner
Back to all Software Engineering Principles Questions→

More Software Engineering Principles Interview Questions

Beginner LevelSoftware Engineering Principles

Explain the 5 SOLID Principles of Object-Oriented Software Design with practical refactoring examples.

Beginner LevelSoftware Engineering Principles

What are DRY (Don't Repeat Yourself), KISS (Keep It Simple, Stupid), and YAGNI (You Aren't Gonna Need It)?

Beginner LevelSoftware Engineering Principles

Why is Composition Over Inheritance a fundamental object-oriented design principle?