-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathmurderrobotdog.go
128 lines (108 loc) · 2.08 KB
/
murderrobotdog.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import "fmt"
// Inspired by this excellent video: https://www.youtube.com/watch?v=wfMtDGfHWpA
// Barker is something that bark
type Barker struct {
Name string
}
// Bark is a noise
func (b Barker) Bark() {
fmt.Printf("Woof, I'm am %s\n", b.Name)
}
// Meower is something that meow
type Meower struct {
Name string
}
// Meow is a noise
func (b Meower) Meow() {
fmt.Printf("Meow, I'm am %s\n", b.Name)
}
// Pooper is something that poop
type Pooper struct{}
// Poop shit happens!
func (p Pooper) Poop() {
fmt.Println("💩💩")
}
// Driver is something that drive
type Driver struct {
Position int
Speed int
}
//Drive is a move
// Your receiver is a pointer because have to change the value
func (d *Driver) Drive() {
d.Position += d.Speed
fmt.Printf("New position: %d\n", d.Position)
}
// Cleaner is something that clean
type Cleaner struct{}
// Clean is an action
func (c Cleaner) Clean() {
fmt.Println("Clean")
}
// Killer is something that kill
type Killer struct{}
// Kill is an action
func (k Killer) Kill() {
fmt.Println("I kill you!")
}
// Dog is a barker that poop
type Dog struct {
Barker
Pooper
}
// Cat is meower that poop
type Cat struct {
Meower
Pooper
}
// CleaningRobot is a driver that clean
type CleaningRobot struct {
Driver
Cleaner
}
// MurderRobot is a driver that kill
type MurderRobot struct {
Driver
Killer
}
// MurderRobotDog WAT?
type MurderRobotDog struct {
MurderRobot
Barker
}
func main() {
// a barker can bark
b := Barker{Name: "Rex"}
b.Bark()
// a meower can meow
m := Meower{Name: "Kitty"}
m.Meow()
// a pooper can poop
p := Pooper{}
p.Poop()
// a driver can drive
d := Driver{Position: 0, Speed: 10}
d.Drive()
// a cleaner can clean
c := Cleaner{}
c.Clean()
// a killer can kil
k := Killer{}
k.Kill()
// a dog can bark and poop
dog := Dog{}
dog.Name = "Fox"
dog.Bark()
dog.Poop()
// a Murder Robot Dog
mrd := MurderRobotDog{
MurderRobot{Driver{Position: 0, Speed: 10}, Killer{}},
Barker{Name: "Murder robot dog!"}}
// can bark
mrd.Bark()
// can drive
mrd.Drive()
// can kill and don't poop!
mrd.Kill()
}