mirror of
https://github.com/vbatts/talks.git
synced 2025-05-24 22:02:29 +00:00
2013-03: adding an old learning lunch
This commit is contained in:
parent
68f582d393
commit
24cea0199b
17 changed files with 718 additions and 0 deletions
39
2013/03-golang-learning-lunch/10-abstracts/main.go
Normal file
39
2013/03-golang-learning-lunch/10-abstracts/main.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
func main() {
|
||||
jeep := Hummer{}
|
||||
h(jeep)
|
||||
jeep.Where()
|
||||
c(jeep)
|
||||
}
|
||||
|
||||
|
||||
type Car interface {
|
||||
Honk()
|
||||
Crank()
|
||||
}
|
||||
|
||||
func c(some interface{}) {
|
||||
some.(Car).Crank()
|
||||
}
|
||||
func h(some interface{}) {
|
||||
some.(Car).Honk()
|
||||
}
|
||||
|
||||
// Implement the Car interface
|
||||
type Hummer struct {
|
||||
Car
|
||||
}
|
||||
|
||||
func (h Hummer) Honk() {
|
||||
println("BEEP BEEP")
|
||||
}
|
||||
|
||||
func (h Hummer) Where() {
|
||||
println("Who's got the keys to the jeep?")
|
||||
}
|
||||
|
||||
func (h Hummer) Crank() {
|
||||
println("VROOOOOOM")
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue