All Articles

Structural Design Pattern: Adapter

This article was done using my notes from:

Alexander Shvets (2019), Dive into Design Patterns, Refactoring.Guru

Adapter

Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate.

Structure

Adapter

Code

class Target:
    def request(self) -> str:
        return "Target: The default target's behavior."


class Adaptee:
    def specific_request(self) -> str:
        return "Special request."


class Adapter(Target, Adaptee):
    def request(self) -> str:
        return f"Adapter: (TRANSLATED) {self.specific_request()}"