-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.go
More file actions
45 lines (39 loc) · 727 Bytes
/
interface.go
File metadata and controls
45 lines (39 loc) · 727 Bytes
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
package main
import (
"math"
"fmt"
)
type Circle struct {
radius float64
}
type Rectangle struct {
width float64
height float64
}
type Geomtery interface {
area() float64
perimeter() float64
}
func (c *Circle) area() (float64) {
return math.Pi * c.radius * c.radius
}
func (c *Circle) perimeter() (float64) {
return 2 * math.Pi * c.radius
}
func (r *Rectangle) area() (float64) {
return r.height * r.width
}
func (r *Rectangle) perimeter() (float64) {
return 2*r.width + 2*r.height
}
//method that will implement the interface struct
func measurement(g Geomtery) {
fmt.Println(g.area())
fmt.Println(g.perimeter())
}
func main() {
c := Circle{23}
measurement(&c)
r := Rectangle{23, 34}
measurement(&r)
}