Go语言适配器模式:接口转换
1. 适配器实现
type Target interface { Request() string } type Adaptee struct{} func (a *Adaptee) SpecificRequest() string { return "SpecificRequest" } type Adapter struct { adaptee *Adaptee } func (a *Adapter) Request() string { return a.adaptee.SpecificRequest() }2. 总结
适配器模式将一个类的接口转换成客户端期望的另一个接口,使原本不兼容的类可以合作。