-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbridge.go
More file actions
57 lines (46 loc) · 1.21 KB
/
bridge.go
File metadata and controls
57 lines (46 loc) · 1.21 KB
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
//main package has examples shown
// in Go Data Structures and algorithms book
package main
// importing fmt package
import (
"fmt"
)
//IDrawShape interface
type IDrawShape interface {
drawShape(x [5]float32, y [5]float32)
}
//DrawShape struct
type DrawShape struct{}
// DrawShape struct has method draw Shape with float x and y coordinates
func (drawShape DrawShape) drawShape(x [5]float32, y [5]float32) {
fmt.Println("Drawing Shape")
}
//IContour interace
type IContour interface {
drawContour(x [5]float32, y [5]float32)
resizeByFactor(factor int)
}
//DrawContour struct
type DrawContour struct {
x [5]float32
y [5]float32
shape DrawShape
factor int
}
//DrawContour method drawContour given the coordinates
func (contour DrawContour) drawContour(x [5]float32, y [5]float32) {
fmt.Println("Drawing Contour")
contour.shape.drawShape(contour.x, contour.y)
}
//DrawContour method resizeByFactor given factor
func (contour DrawContour) resizeByFactor(factor int) {
contour.factor = factor
}
// main method
func main() {
var x = [5]float32{1, 2, 3, 4, 5}
var y = [5]float32{1, 2, 3, 4, 5}
var contour IContour = DrawContour{x, y, DrawShape{}, 2}
contour.drawContour(x, y)
contour.resizeByFactor(2)
}