Can you provide an example of using the Adapter pattern in Java?

A practical example of the Adapter pattern is bridging a modern logging framework with an outdated logging module during a system migration, without modifying either the new framework or the legacy code.

Key Points

Example

A LegacyLoggerAdapter implements the modern Logger interface's log(String message) method by internally calling the old OldLogger.writeToLogFile(message), so new code can log through the modern interface while the legacy module keeps working unchanged.

interface Logger {
    void log(String message);
}

class OldLogger {
    void writeToLogFile(String entry) {
        System.out.println("OLD LOG: " + entry);
    }
}

class LegacyLoggerAdapter implements Logger {
    private OldLogger oldLogger = new OldLogger();

    public void log(String message) {
        oldLogger.writeToLogFile(message);
    }
}

Interview Tip

A concise interview answer is

Say I'm integrating a legacy logging module that only exposes writeToLogFile() into an application that expects a modern Logger interface with a log() method. I write an adapter class that implements Logger and internally calls writeToLogFile(), so the rest of the app logs through the modern interface while the legacy module stays completely untouched.

Last updated: 16 July 2026

Previous question: How does the Adapter pattern differ from the Decorator pattern?

Next question: What are the two types of adapters (class and object adapters), and how do they differ?

More Java Design Patterns interview questions

All Java Design Patterns questions