-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidiomatic.go
84 lines (71 loc) · 1.37 KB
/
idiomatic.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
77
78
79
80
81
82
83
84
package main
import (
"fmt"
)
type EmployeeRole int
const (
Developer EmployeeRole = iota
Tester
ProjectManager
)
type IEmployeeRolePossesor interface {
GetRole() EmployeeRole
}
type IPrintableEmployee interface {
GetPrintString() interface{}
}
type IEmployee interface {
IEmployeeRolePossesor
IPrintableEmployee
}
type EmployeeType struct {
Role EmployeeRole
}
func (e EmployeeType) GetRole() EmployeeRole {
return e.Role
}
type DeveloperType struct {
EmployeeType
Language string
}
func (d DeveloperType) GetPrintString() interface{} {
return "Developer likes to develop in " + d.Language
}
type TesterType struct {
EmployeeType
Framework string
}
func (t TesterType) GetPrintString() interface{} {
return "Tester tests with " + t.Framework
}
type ProjectManagerType struct {
EmployeeType
Methodology string
}
func (p ProjectManagerType) GetPrintString() interface{} {
return "PM delivers using " + p.Methodology
}
var employees = map[int]interface{} {
1: DeveloperType {
EmployeeType : EmployeeType {
Role: Developer,
},
Language : "Go",
},
2: TesterType {
EmployeeType : EmployeeType {
Role: Tester,
},
Framework: "Selenium",
},
3: ProjectManagerType {
EmployeeType : EmployeeType {
Role: ProjectManager,
},
Methodology: "Agile",
},
}
func main() {
employee := employees[1].(IEmployee)
fmt.Printf("%s\n", employee.GetPrintString())
}