Go 多态 如何建表啊?

li_mingxie li_mingxie 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

type Animal interface {
Sleep()
Age() int
Type() string
}
type Cat struct {
MaxAge int
Owner string
}

func (this *Cat) Sleep() {
fmt.Println("Cat need sleep")
}
func (this *Cat) Age() int {
return this.MaxAge
}
func (this *Cat) Type() string {
return this.Owner
}

/*=======================================================*/

type Dog struct {
MaxAge int
}

func (this *Dog) Sleep() {
fmt.Println("Dog need sleep")
}
func (this *Dog) Age() int {
return this.MaxAge
}
func (this *Dog) Type() string {
return "Dog"
}

这我如何建表啊?
以前用C# 有 Animal, Dog, Cat 3个表 而且MaxAge是抽象类的的字段。
Go 只能建Dog, Cat 两个表 各自包含着MaxAge吗?
...全文
评论 2
收藏 已收藏
分享
返回顶部
li_mingxie
go语言 2,351 成员 924 内容