模式 / 结构模式
image

//Adaptee
class StringList {
    rows: string[] = []

    //SpecificRequest()
    getString() {
        return this.rows.join("\n")
    }

    add(value: string) {
        this.rows.push(value)
    }
}

//Adapter
class TextAdapter extends StringList {
    //Request()
    getText(): string {
        return this.getString()
    }
}

function getTextAdapter() {
    let adapter = new TextAdapter()
    adapter.add("line 1")
    adapter.add("line 2")
    return adapter
}

//Client
let adapter = getTextAdapter()
let text = adapter.getText()
//text: line 1
//      line 2
console.log(`text:\n${text}`)