Skip to content

Instantly share code, notes, and snippets.

@coolbrg
Forked from meson10/interfaces.go
Last active August 29, 2015 14:11
Show Gist options
  • Save coolbrg/8744878eb0d144731ed9 to your computer and use it in GitHub Desktop.
Save coolbrg/8744878eb0d144731ed9 to your computer and use it in GitHub Desktop.
package main
import "log"
type EventLogger interface {
Log() int
}
type EventA struct {
Id int
Description string
}
func (e EventA) Log() int {
log.Println(e.Id, e.Description)
return e.Id
}
type EventB struct {
Id int
Description string
Location string
}
func (e EventB) Log() int {
log.Println(e.Id, e.Description, "at", e.Location)
return e.Id
}
func logEvent(e EventLogger) {
e.Log()
}
func main() {
e1 := EventA{123, "Event A without location"}
e2 := EventB{123, "Event B with location", "Pune"}
e1.Log()
logEvent(e1)
logEvent(e2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment