package main

import "fmt"

//继承与接口之间的区别
//猴子生来会爬树,为继承,猴子学会游泳,为接口
/*
	当A结构体继承了B结构体,那么A结构体就自动继承了B结构体的字段和方法,并且可以直接使用
	当A结构体需要扩展功能,同时不希望去破坏继承关系,则可以去实现某个接口即可,因此我们可以认为,实现接口是对继承机制的补充
*/
//Monkey结构体
type Monkey struct {
	Name string
}

//LittleMonkey
type LittleMonkey struct {
	Monkey //继承
}

//Bird能力
type BirdAble interface {
	Flying()
}

//fish能力
type FishAble interface {
	Swiming()
}

func (this *Monkey) climbing() {

	fmt.Println(this.Name, "生来会爬树")
}

func (this *LittleMonkey) Flying() {

	fmt.Println(this.Name, "学会了飞翔")
}
func (this *LittleMonkey) Swiming() {

	fmt.Println(this.Name, "学会了游泳")
}

func main() {

	//创建一个LittleMonkey 实例
	monkey := LittleMonkey{
		Monkey{
			Name: "悟空",
		},
	}
	monkey.climbing()
	monkey.Flying()
	monkey.Swiming()
}