diff options
| author | mo khan <mo.khan@gmail.com> | 2019-10-27 15:30:24 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-10-27 15:30:24 -0600 |
| commit | b77aa05d1e8b783ced758bab329603b2fd2ea9e7 (patch) | |
| tree | 023b77108507d9f46307b51ee2bac6cf4324c072 /shapes.go | |
| parent | 3905316f2920e774a40099bf30c985cbfa099388 (diff) | |
Extract a shape interface
Diffstat (limited to 'shapes.go')
| -rw-r--r-- | shapes.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/shapes.go b/shapes.go new file mode 100644 index 0000000..7853871 --- /dev/null +++ b/shapes.go @@ -0,0 +1,30 @@ +package main + +import ( + "math" +) + +func Perimeter(rectangle Rectangle) float64 { + return 2 * (rectangle.Width + rectangle.Height) +} + +type Shape interface { + Area() float64 +} + +type Rectangle struct { + Width float64 + Height float64 +} + +func (r Rectangle) Area() float64 { + return r.Width * r.Height +} + +type Circle struct { + Radius float64 +} + +func (c Circle) Area() float64 { + return math.Pi * c.Radius * c.Radius +} |
