forked from AlexanderGrom/go-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge.go
56 lines (45 loc) · 1.02 KB
/
bridge.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
// Package bridge is an example of the Bridge Pattern.
package bridge
// Carer provides car interface.
type Carer interface {
Rase() string
}
// Enginer provides engine interface.
type Enginer interface {
GetSound() string
}
// Car implementation.
type Car struct {
engine Enginer
}
// NewCar is the Car constructor.
func NewCar(engine Enginer) Carer {
return &Car{
engine: engine,
}
}
// Rase implementation.
func (c *Car) Rase() string {
return c.engine.GetSound()
}
// EngineSuzuki implements Suzuki engine.
type EngineSuzuki struct {
}
// GetSound returns sound of the engine.
func (e *EngineSuzuki) GetSound() string {
return "SssuuuuZzzuuuuKkiiiii"
}
// EngineHonda implements Honda engine.
type EngineHonda struct {
}
// GetSound returns sound of the engine.
func (e *EngineHonda) GetSound() string {
return "HhoooNnnnnnnnnDddaaaaaaa"
}
// EngineLada implements Lada engine.
type EngineLada struct {
}
// GetSound returns sound of the engine.
func (e *EngineLada) GetSound() string {
return "PhhhhPhhhhPhPhPhPhPh"
}