Last active
November 8, 2016 06:59
-
-
Save bolerap/7ab0a20f868e9ee511cff8c4f17bda5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
// 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