-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathstate.go
61 lines (44 loc) · 1007 Bytes
/
state.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
package behavioral
type State interface {
Approval(m *Machine)
Reject(m *Machine)
Name() string
}
type Machine struct {
state State
}
type leaderApproveState struct{}
type financeApproveState struct{}
func (m *Machine) SetState(s State) {
m.state = s
}
func (m *Machine) StateName() string {
return m.state.Name()
}
func (m *Machine) Approval() {
m.state.Approval(m)
}
func (m *Machine) Reject() {
m.state.Reject(m)
}
func (leaderApproveState) Approval(m *Machine) {
m.SetState(GetFinanceApproveState())
}
func (leaderApproveState) Name() string {
return "LeaderApproveState"
}
func (leaderApproveState) Reject(m *Machine) {}
func GetLeaderApproveState() State {
return &leaderApproveState{}
}
func (financeApproveState) Approval(m *Machine) {
}
func (financeApproveState) Reject(m *Machine) {
m.SetState(GetLeaderApproveState())
}
func (financeApproveState) Name() string {
return "FinanceApproveState"
}
func GetFinanceApproveState() State {
return &financeApproveState{}
}