Skip to content

Commit

Permalink
Add test interface demo (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
caoyingjunz authored Sep 29, 2023
1 parent 84ac612 commit 6b378a1
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions practise/interface-practise/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import "fmt"

type TestInterface interface {
RunTest1()
RunTest2()
RunTest3()
}

type test struct {
*Test1
*Test2
*Test3
}

func NewTest() TestInterface {
return test{
&Test1{Name: "test1"},
&Test2{Name: "test2"},
&Test3{Name: "test3"},
}
}

type Test1 struct {
Name string
}

type Test2 struct {
Name string
}

type Test3 struct {
Name string
}

func (t *Test1) RunTest1() {
fmt.Println(t.Name)
}

func (t *Test2) RunTest2() {
fmt.Println(t.Name)
}

func (t *Test3) RunTest3() {
fmt.Println(t.Name)
}

func main() {
t := NewTest()

t.RunTest1()
t.RunTest2()
t.RunTest3()
}

0 comments on commit 6b378a1

Please sign in to comment.