-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
87 lines (68 loc) · 1.44 KB
/
interfaces.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package singlefile
import "math"
type Shape interface {
Area() float64
isShape()
}
type ShapeUnion interface {
Area() float64
isShapeUnion()
}
type Circle struct {
Radius float64
Coordinates
}
func (c *Circle) Area() float64 {
return c.Radius * math.Pi * math.Pi
}
func (c *Circle) isShapeUnion() {}
func (c *Circle) isShape() {}
type Rectangle struct {
Length, Width float64
Coordinates
}
func (r *Rectangle) Area() float64 {
return r.Length * r.Width
}
func (r *Rectangle) isShapeUnion() {}
func (r *Rectangle) isShape() {}
type Node interface {
Child() (Node, error)
}
type ConcreteNodeA struct {
ID string
Name string
child Node
}
func (n *ConcreteNodeA) Child() (Node, error) {
return n.child, nil
}
// Implements the Node interface with another interface
type ConcreteNodeInterface interface {
Node
ID() string
}
type ConcreteNodeInterfaceImplementor struct{}
func (c ConcreteNodeInterfaceImplementor) ID() string {
return "CNII"
}
func (c ConcreteNodeInterfaceImplementor) Child() (Node, error) {
return &ConcreteNodeA{
ID: "Child",
Name: "child",
}, nil
}
type BackedByInterface interface {
ThisShouldBind() string
ThisShouldBindWithError() (string, error)
}
type BackedByInterfaceImpl struct {
Value string
Error error
}
func (b *BackedByInterfaceImpl) ThisShouldBind() string {
return b.Value
}
func (b *BackedByInterfaceImpl) ThisShouldBindWithError() (string, error) {
return b.Value, b.Error
}