trying_out_go/pkg/gadget/program.go

34 lines
561 B
Go
Raw Normal View History

package main
type Player interface {
Play(string)
Stop()
}
func TryOut(player Player) {
player.Play("Test Track")
player.Stop()
recorder, ok := player.(TapeRecorder)
if ok {
recorder.Record()
}
}
func playList(device Player, songs []string) {
for _, song := range songs {
device.Play(song)
}
device.Stop()
}
func main() {
mixTape := []string{"Jessie's Girl", "Whip It", "9 to 5"}
var player Player = TapePlayer{}
playList(player, mixTape)
player = TapeRecorder{}
playList(player, mixTape)
TryOut(TapeRecorder{})
TryOut(TapePlayer{})
}