-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bridge.go
62 lines (50 loc) · 1.04 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
57
58
59
60
61
62
package main
import "fmt"
type ICoffee interface {
OrderCoffee(count int)
}
type LargeCoffee struct {
additives ICoffeeAdditives
}
func (l *LargeCoffee) OrderCoffee(count int) {
fmt.Print("Large Coffee ")
l.additives.AddAdditives()
fmt.Println(count, " cup")
}
type SmallCoffee struct {
additives ICoffeeAdditives
}
func (s *SmallCoffee) OrderCoffee(count int) {
fmt.Print("Small Coffee ")
s.additives.AddAdditives()
fmt.Println(count, "cup")
}
type ICoffeeAdditives interface {
AddAdditives()
}
type Milk struct{}
func (m *Milk) AddAdditives() {
fmt.Print("With Milk ")
}
type Sugar struct{}
func (s *Sugar) AddAdditives() {
fmt.Print("With Sugar ")
}
func main() {
largeCoffeeMilk := LargeCoffee{
additives: &Milk{},
}
largeCoffeeMilk.OrderCoffee(1)
smallCoffeeMilk := SmallCoffee{
additives: &Milk{},
}
smallCoffeeMilk.OrderCoffee(1)
largeCoffeeSugar := LargeCoffee{
additives: &Sugar{},
}
largeCoffeeSugar.OrderCoffee(1)
smallCoffeeMSugar := SmallCoffee{
additives: &Sugar{},
}
smallCoffeeMSugar.OrderCoffee(1)
}