From 8b66bf7fcbae5648002facf25f58052fbee6ae03 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Sun, 19 Apr 2015 08:26:23 -0700 Subject: [PATCH] A square can't have different width and height --- examples/interfaces/interfaces.go | 20 ++++++++++---------- examples/interfaces/interfaces.hash | 4 ++-- public/interfaces | 22 +++++++++++----------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/interfaces/interfaces.go b/examples/interfaces/interfaces.go index eda6539..2df7234 100644 --- a/examples/interfaces/interfaces.go +++ b/examples/interfaces/interfaces.go @@ -13,8 +13,8 @@ type geometry interface { } // For our example we'll implement this interface on -// `square` and `circle` types. -type square struct { +// `rect` and `circle` types. +type rect struct { width, height float64 } type circle struct { @@ -23,12 +23,12 @@ type circle struct { // To implement an interface in Go, we just need to // implement all the methods in the interface. Here we -// implement `geometry` on `square`s. -func (s square) area() float64 { - return s.width * s.height +// implement `geometry` on `rect`s. +func (r rect) area() float64 { + return r.width * r.height } -func (s square) perim() float64 { - return 2*s.width + 2*s.height +func (r rect) perim() float64 { + return 2*r.width + 2*r.height } // The implementation for `circle`s. @@ -50,13 +50,13 @@ func measure(g geometry) { } func main() { - s := square{width: 3, height: 4} + r := rect{width: 3, height: 4} c := circle{radius: 5} - // The `circle` and `square` struct types both + // The `circle` and `rect` struct types both // implement the `geometry` interface so we can use // instances of // these structs as arguments to `measure`. - measure(s) + measure(r) measure(c) } diff --git a/examples/interfaces/interfaces.hash b/examples/interfaces/interfaces.hash index cc601b5..aa81b50 100644 --- a/examples/interfaces/interfaces.hash +++ b/examples/interfaces/interfaces.hash @@ -1,2 +1,2 @@ -9bafbade1f5effc38be233c3fd12cbdd7c6e226d -guxTzcucR- +3547b935d1e0322c0fb696726c27cae53a275e0a +313UebA3rD diff --git a/public/interfaces b/public/interfaces index 2007c74..605acca 100644 --- a/public/interfaces +++ b/public/interfaces @@ -40,7 +40,7 @@ signatures.

- +
package main
 
@@ -79,12 +79,12 @@ signatures.

For our example we’ll implement this interface on -square and circle types.

+rect and circle types.

-
type square struct {
+            
type rect struct {
     width, height float64
 }
 type circle struct {
@@ -99,16 +99,16 @@ signatures.

To implement an interface in Go, we just need to implement all the methods in the interface. Here we -implement geometry on squares.

+implement geometry on rects.

-
func (s square) area() float64 {
-    return s.width * s.height
+            
func (r rect) area() float64 {
+    return r.width * r.height
 }
-func (s square) perim() float64 {
-    return 2*s.width + 2*s.height
+func (r rect) perim() float64 {
+    return 2*r.width + 2*r.height
 }
 
@@ -160,7 +160,7 @@ to work on any geometry.

func main() {
-    s := square{width: 3, height: 4}
+    r := rect{width: 3, height: 4}
     c := circle{radius: 5}
 
@@ -169,7 +169,7 @@ to work on any geometry.

-

The circle and square struct types both +

The circle and rect struct types both implement the geometry interface so we can use instances of these structs as arguments to measure.

@@ -177,7 +177,7 @@ these structs as arguments to measure.

-
    measure(s)
+            
    measure(r)
     measure(c)
 }