DEV Community

eidher
eidher

Posted on β€’ Edited on

3

Adapter Pattern

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
Alt Text

Participants

  • Target: defines the domain-specific interface that Client uses.
  • Adapter: adapts the interface Adaptee to the Target interface.
  • Adaptee: defines an existing interface that needs adapting.
  • Client: collaborates with objects conforming to the Target interface.

Code

public class Main {

    public static void main(String[] args) {
        Target target = new Adapter();
        target.request();
    }
}

public interface Target {
    void request();
}

public class Adapter implements Target {
    Adaptee adaptee = new Adaptee();

    @Override
    public void request() {
        adaptee.specificRequest();
    }
}

public class Adaptee {
    void specificRequest() {
        System.out.println("Called specificRequest()");
    }
}

Enter fullscreen mode Exit fullscreen mode

Output

Called specificRequest()
Enter fullscreen mode Exit fullscreen mode

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (0)

Image of DataStax

Langflow: Simplify AI Agent Building

Connect models, vector stores, memory and other AI building blocks with the click of a button to build and deploy AI-powered agents.

Get started for free

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay