forked from AlexanderGrom/go-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
facade.go
59 lines (49 loc) · 916 Bytes
/
facade.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
// Package facade is an example of the Facade Pattern.
package facade
import (
"strings"
)
// NewMan creates man.
func NewMan() *Man {
return &Man{
house: &House{},
tree: &Tree{},
child: &Child{},
}
}
// Man implements man and facade.
type Man struct {
house *House
tree *Tree
child *Child
}
// Todo returns that man must do.
func (m *Man) Todo() string {
result := []string{
m.house.Build(),
m.tree.Grow(),
m.child.Born(),
}
return strings.Join(result, "\n")
}
// House implements a subsystem "House"
type House struct {
}
// Build implementation.
func (h *House) Build() string {
return "Build house"
}
// Tree implements a subsystem "Tree"
type Tree struct {
}
// Grow implementation.
func (t *Tree) Grow() string {
return "Tree grow"
}
// Child implements a subsystem "Child"
type Child struct {
}
// Born implementation.
func (c *Child) Born() string {
return "Child born"
}