This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Foo struct { | |
Foo1 int | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Vehicle struct { | |
speed int | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a := NewAmphibian() | |
a.Accelerate(10) | |
a.Swim(true) | |
a.Accelerate(20) | |
fmt.Printf("amphibian speed swimming: %d kph\n", a.Speed()) | |
a.Swim(false) | |
fmt.Printf("amphibian speed on land: %d kph\n", a.Speed()) | |
var d Drivable | |
d = a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ype Amphibian struct { | |
Car | |
Boat | |
swimming bool | |
} | |
func NewAmphibian() *Amphibian { | |
a := new(Amphibian) | |
a.swimming = false | |
return a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vehicle.go:65: Amphibian.Accelerate is ambiguous | |
vehicle.go:65: cannot use a (type *Amphibian) as type Drivable in return argument: | |
*Amphibian does not implement Drivable (missing Accelerate method) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Amphibian struct { | |
Car | |
Boat | |
} | |
func NewAmphibian() Drivable { | |
a := new(Amphibian) | |
return a | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Boat struct { | |
Vehicle | |
} | |
func(b *Boat) Accelerate(delta uint) { | |
b.Vehicle.speed += int(delta) | |
} | |
func(b *Boat) Brake(delta uint) { | |
b.Vehicle.speed -= int(delta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Car struct { | |
Vehicle | |
} | |
func(c *Car) Accelerate(delta uint) { | |
c.Vehicle.speed += int(delta) | |
} | |
func(c *Car) Brake(delta uint) { | |
c.Vehicle.speed -= int(delta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Car struct { | |
Vehicle | |
} | |
func(c *Car) Accelerate(delta uint) { | |
c.Vehicle.speed += int(delta) | |
} | |
func(c *Car) Brake(delta uint) { | |
c.Vehicle.speed -= int(delta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Drivable interface { | |
Accelerate(delta uint) | |
Brake(delta uint) | |
Speed() int | |
} |