/
19template.go
65 lines (58 loc) · 1.07 KB
/
19template.go
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
/**
@author: Jason Pang
@desc:
@date: 2021/7/1
**/
package design
import "fmt"
/**
* @Author: Jason Pang
* @Description: 试卷
*/
type Examination struct {
//函数变量,回答问题1
Answer1 func()
//函数变量,回答问题2
Answer2 func()
}
/**
* @Author: Jason Pang
* @Description: 问题列表,也是算法骨架
* @receiver e
*/
func (e *Examination) Questions() {
fmt.Println("第一题:谁是最帅的人?")
e.Answer1()
fmt.Println("第二题:生活的意义是什么?")
e.Answer2()
}
/**
* @Author: Jason Pang
* @Description: 真正做试卷
*/
type ExamplationDo struct {
Examination
}
/**
* @Author: Jason Pang
* @Description: 写答案1
* @receiver d
*/
func (d *ExamplationDo) Answer1() {
fmt.Println("答案:我自己")
}
/**
* @Author: Jason Pang
* @Description: 写答案2
* @receiver d
*/
func (d *ExamplationDo) Answer2() {
fmt.Println("答案:躺平")
}
func templateMain() {
e := &ExamplationDo{}
//需要对父类函数进行赋值
e.Examination.Answer1 = e.Answer1
e.Examination.Answer2 = e.Answer2
e.Questions()
}