Skip to content

Instantly share code, notes, and snippets.

@davidpatters0n
Created January 7, 2019 15:02
Show Gist options
  • Save davidpatters0n/2ee0aba290cee24b9f5eef717567818a to your computer and use it in GitHub Desktop.
Save davidpatters0n/2ee0aba290cee24b9f5eef717567818a to your computer and use it in GitHub Desktop.
Go interface composition
// https://play.golang.org/p/AjNOxAM4GMt
package main
import "fmt"
type I interface {
J
i() string
}
type J interface {
K
j() string
}
type K interface {
k() string
}
type T struct {}
func (T) i() string { return "I am from I" }
func (T) j() string { return "I am from J" }
func (T) k() string { return "I am from K" }
func main() {
var i I = T{}
fmt.Println(i.k())
}
class K
def k
"I am from K"
end
end
class J < K
def j
"I am from J"
end
end
class I < J
def i
"I am from I"
end
end
###
# i = I.new
# i.k
# => I am from K
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment