-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstructs.go
More file actions
81 lines (61 loc) · 930 Bytes
/
structs.go
File metadata and controls
81 lines (61 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
)
type SuperType interface {
GetName() string
GetMessage() string
CallSecond()
}
type A struct{}
func (a *A) CallFirst() {
fmt.Println("A CallFirst")
}
func (a *A) CallSecond() {
a.callSecond(a)
}
func (a *A) callSecond(s SuperType) {
fmt.Println(s.GetName(), s.GetMessage())
}
func (a *A) GetName() string {
return "A"
}
func (a *A) GetMessage() string {
return "CallSecond"
}
type B struct {
A
}
func (b *B) CallFirst() {
fmt.Println("B CallFirst")
}
func (b *B) GetName() string {
return "B"
}
func (b *B) CallSecond() {
b.callSecond(b)
}
type C struct {
A
}
func (c *C) GetName() string {
return "C"
}
func (c *C) CallSecond() {
c.callSecond(c)
}
func main() {
a := new(A)
a.CallFirst()
b := new(B)
b.CallFirst()
a.CallSecond()
b.CallSecond()
c := new(C)
DoSomething(a)
DoSomething(b)
DoSomething(c)
}
func DoSomething(s SuperType) {
s.CallSecond()
}