forked from AlexanderGrom/go-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.go
45 lines (36 loc) · 1.07 KB
/
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
// Package state is an example of the State Pattern.
package state
// MobileAlertStater provides a common interface for various states.
type MobileAlertStater interface {
Alert() string
}
// MobileAlert implements an alert depending on its state.
type MobileAlert struct {
state MobileAlertStater
}
// Alert returns a alert string
func (a *MobileAlert) Alert() string {
return a.state.Alert()
}
// SetState changes state
func (a *MobileAlert) SetState(state MobileAlertStater) {
a.state = state
}
// NewMobileAlert is the MobileAlert constructor.
func NewMobileAlert() *MobileAlert {
return &MobileAlert{state: &MobileAlertVibration{}}
}
// MobileAlertVibration implements vibration alert
type MobileAlertVibration struct {
}
// Alert returns a alert string
func (a *MobileAlertVibration) Alert() string {
return "Vrrr... Brrr... Vrrr..."
}
// MobileAlertSong implements beep alert
type MobileAlertSong struct {
}
// Alert returns a alert string
func (a *MobileAlertSong) Alert() string {
return "Белые розы, Белые розы. Беззащитны шипы..."
}