-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (59 loc) · 1.54 KB
/
main.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
package main
import (
"fmt"
"example.com/patterns/api"
"example.com/patterns/processor"
)
func main() {
// Plain old data
// Not immutable, but doesn't matter if this action is event driven
// eg: state in -> state out by the end of this function
objects := []interface{}{
&api.Place{
Name: "Glastonbury",
},
&api.Person{
Name: "Jack",
Occupation: "Footballer",
Place: "Totenham",
},
&api.Person{
Name: "Mary",
Occupation: "Cartographer",
Place: "Glastonbury",
},
&api.Place{
Name: "Totenham",
},
}
fmt.Println("\n###########################")
fmt.Println("# Data Objects")
fmt.Println("###########################\n")
printPodos(objects)
processableObjects := processor.MakeProcessable(objects)
processableObjects.Process()
fmt.Println("\n###########################")
fmt.Println("# Proving it")
fmt.Println("###########################\n")
processableObjects.Process()
fmt.Println("\n###########################")
fmt.Println("# mutated but not decorated")
fmt.Println("###########################\n")
printPodos(objects)
}
func printPodos(objects []interface{}) {
for _, podo := range objects {
switch v := podo.(type) {
case *api.Place:
fmt.Println("Place:")
fmt.Printf("\tName:%s\n", v.Name)
fmt.Printf("\tLocation:%+v\n", v.Location)
case *api.Person:
fmt.Println("Person:")
fmt.Printf("\tName:%s\n", v.Name)
fmt.Printf("\tOccupation:%s\n", v.Occupation)
fmt.Printf("\tPlace:%s\n", v.Place)
fmt.Printf("\tLocation:%+v\n", v.Location)
}
}
}