-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
52 lines (43 loc) · 1.45 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
package main
import (
"compound/quackable/composite"
"compound/quackable/decorator"
"compound/quackable/duck/adpater"
"compound/quackable/factory"
"compound/quackable/goose"
"compound/quackable/observer"
"fmt"
)
func main() {
// 오리 팩토리 생성
countingDuckFactory := factory.CountingDuckFactory{}
// 오리떼 생성
mallardDuckOne := countingDuckFactory.CreateMallardDuck()
mallardDuckTwo := countingDuckFactory.CreateMallardDuck()
mallardDuckThree := countingDuckFactory.CreateMallardDuck()
mallardDuckFour := countingDuckFactory.CreateMallardDuck()
redheadDuck := countingDuckFactory.CreateRedheadDuck()
duckCall := countingDuckFactory.CreateDuckCall()
rubberDuck := countingDuckFactory.CreateRubberDuck()
// 어뎁터 적용
gooseDuck := adpater.GooseAdapter{Goose: goose.Goose{}}
// 오리떼 집합 관리
flockOfDucks := composite.NewFlock()
flockOfDucks.Add(redheadDuck)
flockOfDucks.Add(duckCall)
flockOfDucks.Add(rubberDuck)
flockOfDucks.Add(gooseDuck)
flockOfMallards := composite.NewFlock()
flockOfMallards.Add(mallardDuckOne)
flockOfMallards.Add(mallardDuckTwo)
flockOfMallards.Add(mallardDuckThree)
flockOfMallards.Add(mallardDuckFour)
flockOfDucks.Add(flockOfMallards)
// 옵저버
quackologist := &observer.Quackologist{}
flockOfDucks.Register(quackologist)
flockOfDucks.Quack()
fmt.Println("Quack count:", decorator.NumberOfQuack)
flockOfMallards.Quack()
fmt.Println("Quack count:", decorator.NumberOfQuack)
}