-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprototype.go
More file actions
79 lines (61 loc) · 1.15 KB
/
Copy pathprototype.go
File metadata and controls
79 lines (61 loc) · 1.15 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package prototype
type Cloneable interface {
Clone() Cloneable
}
type Shape interface {
GetId() int
GetType() string
SetId() int
}
type Manager struct {
Items map[string]Cloneable
}
func NewPrototypeManage() *Manager {
return &Manager{Items: make(map[string]Cloneable)}
}
func (m *Manager) Get(name string) Cloneable {
c, ok := m.Items[name]
if !ok {
return nil
}
return c.Clone()
}
func (m *Manager) Set(name string, cloneable Cloneable) {
m.Items[name] = cloneable
}
type Circle struct {
Id int
Type string
}
func (circle *Circle)GetId() int {
return circle.Id
}
func (circle *Circle)GetType() string {
return "circle"
}
func (circle *Circle) SetId(id int) int {
circle.Id = id
return circle.Id
}
func (circle *Circle) Clone() Cloneable {
circle2 := *circle
return &circle2
}
type Rectangle struct {
Id int
Type string
}
func (rectangle *Rectangle)GetId() int {
return rectangle.Id
}
func (rectangle *Rectangle)GetType() string {
return "circle"
}
func (rectangle *Rectangle) SetId(id int) int {
rectangle.Id = id
return rectangle.Id
}
func (rectangle *Rectangle) Clone() Cloneable {
rectangle2 := *rectangle
return &rectangle2
}