@Ovenvan 嘗試編碼之后發(fā)現(xiàn)了其中的差別!雖然是淺顯的問題,博主還是耐心解答,非常感謝!
Golang的垂直組合思維——type embedding什么是Golang的正交組合-垂直組合思維:Tony Bai的博客 - Coding in GO way - Orthogonal Composition Go語言通過typ...
@Ovenvan 嘗試編碼之后發(fā)現(xiàn)了其中的差別!雖然是淺顯的問題,博主還是耐心解答,非常感謝!
Golang的垂直組合思維——type embedding什么是Golang的正交組合-垂直組合思維:Tony Bai的博客 - Coding in GO way - Orthogonal Composition Go語言通過typ...
//object/creature/creature.go
package creature
import (
"fmt"
"github.com/ovenvan/multi-inheritance/object"
)
type Creature interface {
object.Object
Create()
}
type Crea struct {
object.Obj //struct 中綁定interface和struct的區(qū)別?
// Object只實現(xiàn)了一個Obj實例,這個實例的作用是被繼承,提供父類的代碼,因此應(yīng)該繼承Obj,而非Object
}
func (t *Crea) Create(){
fmt.Println("This is a Base Create Method")
}
func (t *Crea)GetID() uint{ //override
fmt.Println("Override GetID from Creature")
return t.Obj.GetID()
//t.GetID() it is a recursive call
}
為什么在Crea要override GetID()?這樣不就達不到減少冗余代碼的目的了嗎?
注釋中的recursive call會產(chǎn)生什么問題?
Golang的垂直組合思維——type embedding什么是Golang的正交組合-垂直組合思維:Tony Bai的博客 - Coding in GO way - Orthogonal Composition Go語言通過typ...