-
Notifications
You must be signed in to change notification settings - Fork 15
/
27interpreter.go
76 lines (68 loc) · 1.32 KB
/
27interpreter.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
66
67
68
69
70
71
72
73
74
75
76
/**
@author: Jason Pang
@desc:
@date: 2021/9/1
**/
package design
import "fmt"
/**
* @Author: Jason Pang
* @Description: 内容信息
*/
type Context struct {
action string
content string
}
/**
* @Author: Jason Pang
* @Description: 翻译接口
*/
type Interpreter interface {
Interpret(c Context)
}
/**
* @Author: Jason Pang
* @Description: 翻译音乐
*/
type MusicInterpreter struct {
}
/**
* @Author: Jason Pang
* @Description: 翻译音乐内容
* @receiver m
* @param c
*/
func (m MusicInterpreter) Interpret(c Context) {
fmt.Println(c.action + " 中 " + c.content + " 的意思是感情高昂")
}
/**
* @Author: Jason Pang
* @Description: 翻译舞蹈
*/
type DanceInterpreter struct {
}
/**
* @Author: Jason Pang
* @Description: 翻译舞蹈内容
* @receiver d
* @param c
*/
func (d DanceInterpreter) Interpret(c Context) {
fmt.Println(c.action + " 中 " + c.content + " 的意思是悲凉")
}
func interpreterMain() {
cList := []Context{
{action: "music", content: "高音"},
{action: "music", content: "低音"},
{action: "dance", content: "跳跃"},
{action: "dance", content: "挥手"},
}
//对歌舞剧内容进行翻译
for _, c := range cList {
if c.action == "music" {
MusicInterpreter{}.Interpret(c)
} else if c.action == "dance" {
DanceInterpreter{}.Interpret(c)
}
}
}