Adapter Design Pattern in Java

Adapter pattern – one of the structural patterns – bridges the gap between two incompatible interfaces. This means that we can make classes work together that cannot otherwise because of incompatible interfaces. There are two approaches for implementing Adapter Pattern – class adapter and object adapter, however both approaches produce the same result. A class adapter uses multiple inheritance (by extending one class and/or implementing one or more interfaces) to adapt one interface to another. An object adapter uses Java composition by implementing one or more interfaces.

A real life example could be a case of mobile charger which acts as an adapter between wall socket and a mobile socket, because mobile battery needs 3 volts to charge but the normal socket produces much more than that. Continue reading “Adapter Design Pattern in Java”