美文网首页
GO语言之接口嵌套

GO语言之接口嵌套

作者: 测试探索 | 来源:发表于2020-06-06 16:23 被阅读0次
package main

import "fmt"

func main(){
    var cat Cat = Cat{}
    cat.test1()//test1()...
    cat.test2() //test2()...
    cat.test3() //test3()...

    fmt.Println("----------------")
    var a1 A = cat
    a1.test1()  //test1()...

    var b1 B = cat
    b1.test2()  //test2()...

    var c1 C = cat
    c1.test1() //test1()...
    c1.test2() //test2()...
    c1.test3() //test3()...
}
//定义接口
type A interface {
    test1()
}
//定义接口
type B interface {
    test2()
}
//定义接口
type C interface {
    A
    B
    test3()
}

//2.实现类
type Cat struct { //如果想实现接口从,那不止要实现接口c的方法,还要实现接口A,B中方法

}

//连接实现类来实现接口
func (c Cat) test1(){
    fmt.Println("test1()...")
}

func (c Cat) test2(){
    fmt.Println("test2()...")
}

func (c Cat) test3(){
    fmt.Println("test3()...")
}




image.png

相关文章

  • GO语言之接口嵌套

  • Go语言之接口

    接口定义     面向对象世界中的接口一般定义是“接口定义对象的行为”,它表示让制定个对象应该做什么,实现这种行为...

  • Go语言之接口

    接口 接口类型是对其他类型行为的概括与抽象。通过使用接口,我们可以写出更加灵活和通用的函数,这些函数不用绑定在一个...

  • Go 接口嵌套组合的使用方法 & gomock 测试 stub

    Go 接口嵌套组合的使用方法 gomock 测试 stub 代码生成 使用 -aux_files 指定内嵌接口的 ...

  • Go语言之结构体嵌套

    Go语言之结构体嵌套 在type Student2 struct结构体中,注意book参数引用的是地址,方便修改数据

  • Go语言之接口interfance

    一. 接口 1. 概述 接口类型具体描述了一系列方法的集合 接口类型是一个抽象的类型,不会暴露出他代表的对象内部值...

  • Go语言之空接口

    空接口 不包含任何的方法,正因为如此,所有的类型都实现了空接口,因此空接口可以存储任意类型的数值

  • Go语言之接口断言

    前景 因为空接口interface{}没有定义任何函数,因此Go中所有类型都实现了空接口。当一个函数的形参是int...

  • Go语言之Interface(一)

    Go语言之Interface(一) 什么是interface 在面向对象语言中接口是:接口定义了一个对象的行为,但...

  • Go语言之Interface(一)

    Go语言之Interface(一) 什么是interface 在面向对象语言中接口是:接口定义了一个对象的行为,但...

网友评论

      本文标题:GO语言之接口嵌套

      本文链接:https://www.haomeiwen.com/subject/nuewzhtx.html