Adapter Design Pattern
Arnob Deb
Lecturer, Daffodil International University
What is Adapter Design Pattern?
• - Structural design pattern that allows
incompatible interfaces to work together.
• - Acts as a bridge between two incompatible
classes.
• - Converts one interface into another that a
client expects.
Bonus Answer
• // 🎯 Target Interface (Expected Format - European Plug)
• interface EuropeanPlug {
• void connectEuropeanSocket();
• }
• // 🔌 Adaptee (Existing but incompatible - US Plug)
• class USPlug {
• public void connectUSSocket() {
• [Link]("Connected to US socket.");
• }
• }
• // 🔄 Adapter (Converts US Plug into European Plug)
• class PlugAdapter implements EuropeanPlug {
• private USPlug usPlug; // Store the US Plug
• public PlugAdapter(USPlug usPlug) {
• [Link] = usPlug; // Initialize with the US plug
• }
• @Override
• public void connectEuropeanSocket() {
• [Link]("Adapter converts US plug to fit European socket.");
• [Link](); // Calls the existing US plug method
• }
• }
• // 🚀 Client Code (Using the adapter)
• public class AdapterExample {
• public static void main(String[] args) {
• USPlug usPlug = new USPlug(); // Create a US plug
• EuropeanPlug adapter = new PlugAdapter(usPlug); // Use adapter
• [Link](); // Now it works in a European socket!
• }
• }