Open
Description
Go面向对象编程6——嵌入 interface
在前面的课程中我们已经知道在结构体中可以嵌入匿名字段,其实在接口里也可以再嵌入接口。如果一个 interface1 作为 interface2 的一个嵌入字段,那么 interface2 隐式的包含了 interface1 里的方法。如下例子中,Interface2 包含了 Interface1 的所有方法。
type Interface1 interface {
Send()
Receive()
}
type Interface2 interface {
Interface1
Close()
}
blog link Go面向对象编程6——嵌入 interface