Skip to main content

Adapter Pattern

Learn Adapter Pattern (Structural Patterns, Design Patterns in Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Adapter Pattern lets two incompatible interfaces work together by wrapping one of them in an object (the adapter) that translates calls between them. Real-Life Example: A travel plug adapter that lets a US plug fit into an Indian socket A memory card reader that lets an SD card connect to a USB port Java's own Arrays.asList() adapting an array to the List interface Why do we need Adapter? To reuse existing/legacy code that has an incompatible interface, without modifying it To let two independently-developed classes collaborate To integrate a third-party library's class into your own interface

More lessons in Structural Patterns