Skip to main content

Command Palette

Search for a command to run...

Adapter Pattern

Published
•1 min read•View as Markdown
Adapter Pattern

Why Adapter Pattern

Solution

Class Diagram

Object and Class adapter

Above class diagram is for object adapter, below is class adapter.

  1. Object uses composition, class uses subclassing.

Let's take a example of Enumeration and Iterator. Task is to Adapt an Enumeration to an Iterator.

for remove() we will send UnsupportedOperationException.

Home Work - Adapt an Iterator to Enumerator

Decorator - Doesn't alter the interface, but adds responsibility.

Adapter - Converts one interface to another.

Facade - Makes an interface simpler.