-
Notifications
You must be signed in to change notification settings - Fork 79
/
facade.go
89 lines (73 loc) · 2.12 KB
/
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
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
package structural
import (
"fmt"
)
// CarModel is the first car subsystem which describes the car model.
type CarModel struct {
}
// NewCarModel creates a new car model.
func NewCarModel() *CarModel {
return &CarModel{}
}
// SetModel sets the car model and logs.
func (c *CarModel) SetModel() {
fmt.Fprintf(outputWriter, " CarModel - SetModel\n")
}
// CarEngine is the second car subsystem which describes the car engine.
type CarEngine struct {
}
// NewCarEngine creates a new car engine.
func NewCarEngine() *CarEngine {
return &CarEngine{}
}
// SetEngine sets the car engine and logs.
func (c *CarEngine) SetEngine() {
fmt.Fprintf(outputWriter, " CarEngine - SetEngine\n")
}
// CarBody is the third car subsystem which describes the car body.
type CarBody struct {
}
// NewCarBody creates a new car body.
func NewCarBody() *CarBody {
return &CarBody{}
}
// SetBody sets the car body and logs.
func (c *CarBody) SetBody() {
fmt.Fprintf(outputWriter, " CarBody - SetBody\n")
}
// CarAccessories is the fourth car subsystem which describes the car accessories.
type CarAccessories struct {
}
// NewCarAccessories creates new car accessories.
func NewCarAccessories() *CarAccessories {
return &CarAccessories{}
}
// SetAccessories sets the car accessories and logs.
func (c *CarAccessories) SetAccessories() {
fmt.Fprintf(outputWriter, " CarAccessories - SetAccessories\n")
}
// CarFacade describes the car facade which provides a simplified interface to create a car.
type CarFacade struct {
accessories *CarAccessories
body *CarBody
engine *CarEngine
model *CarModel
}
// NewCarFacade creates a new CarFacade.
func NewCarFacade() *CarFacade {
return &CarFacade{
accessories: NewCarAccessories(),
body: NewCarBody(),
engine: NewCarEngine(),
model: NewCarModel(),
}
}
// CreateCompleteCar creates a new complete car.
func (c *CarFacade) CreateCompleteCar() {
fmt.Fprintf(outputWriter, "******** Creating a Car **********\n")
c.model.SetModel()
c.engine.SetEngine()
c.body.SetBody()
c.accessories.SetAccessories()
fmt.Fprintf(outputWriter, "******** Car creation is completed. **********\n")
}