Adapter: is an example of a class may be implemented by a function that does not function adapter
Adapt Package Import ( "FMT" ) type struct {// ChargeHeadB the charging head B } FUNC (the this ChargeHeadB *) ChargeB () { fmt.Println ( "Head B CHARGE READY to ...") } type ChargeIfC struct {/ / C interface adapter TypeB // adapter B } type interface TypeB { ChargeB () } FUNC NewHead () TypeB { return & ChargeHeadB {} } FUNC (the this ChargeIfC *) ChargeB () {// C for the adapter to a C de-charging this.ChargeC () } FUNC (the this ChargeIfC *) ChargeC () { fmt.Println ( "charging TypeC iS ...") } FUNC AdaptBtoC (B TypeB) TypeB { return {& ChargeIfC TypeB: B, } }
b: = adapt.NewHead () // Create a new charging head B C: = adapt.AdaptBtoC (B) c.ChargeB ()