Skip to content

Instantly share code, notes, and snippets.

@bolerap
Last active November 8, 2016 06:59
Show Gist options
  • Save bolerap/7ab0a20f868e9ee511cff8c4f17bda5d to your computer and use it in GitHub Desktop.
Save bolerap/7ab0a20f868e9ee511cff8c4f17bda5d to your computer and use it in GitHub Desktop.
package main
import "fmt"
// define interfaces
type Vehicle interface {
Move() string
}
// define structs and implement Vehicle interface
type Car struct {}
func (c Car) Move() string {
return "The car is moving"
}
type Bike struct {}
func (b Bike) Move() string {
return "The bike is moving"
}
func main() {
vehicles := []Vehicle{Car{}, Bike{}}
for _, vehicle := range vehicles {
fmt.Println(vehicle.Move())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment