Adapter design pattern is a structural design pattern.
Definition:
Adapter design pattern converts the interface of a class to another interface that client expects, adapter let's classes work together that couldn't otherwise because of incompatible interfaces
Reference from Head First Design Patterns
There are two variant of Adapter design pattern:
- Object Adapter
- Class Adapter
Object adapter pattern uses composition, class adapter pattern uses inheritance. (It's not possible to implement class adapter pattern in java as multiple inheritance is not supported)
UML diagram of an adapter design pattern:
Use Cases:
Adapter pattern is used as a bridge/wrapper to work with legacy code.
public interface Target {
public void request();
}
public interface Adaptee {
public void processRequest();
}
public class Adapter implements Target {
private Adaptee adaptee;
public Adapter(Adaptee adaptee) {
this.adaptee = adaptee;
}
public void request() {
adaptee.processRequest();
}
}


Top comments (0)