模式 / 结构模式
image

from abc import ABCabstractmethod

# Target
class IText(ABC):
    @abstractmethod
    def get_text(self) -> str:
        # Request()
        pass

# Adaptee
class StringList:
    def __init__(self):
        self.rowslist[str] = []

    def add(self, value: str) -> None:
        self.rows.append(value)

    def get_string(self) -> str:
        # SpecificRequest()
        return "\n".join(self.rows)

# Adapter
class TextAdapter(StringListIText):
    def get_text(self) -> str:
        # Request() delegates to SpecificRequest()
        return self.get_string()

# Client
adapter = TextAdapter()
adapter.add("line 1")
adapter.add("line 2")
print(adapter.get_text())
# Output: line 1
#         line 2