Created
April 7, 2015 20:59
-
-
Save olix0r/03c6e6ae30befc79abc2 to your computer and use it in GitHub Desktop.
Adapters in go
This file contains 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 | |
type Goaled interface { | |
Goaled() bool | |
} | |
type Sane interface { | |
Sane() bool | |
} | |
func (goaled Goaled) Sane() bool { | |
return !goaled.Goaled() | |
} | |
func main() { | |
} |
This file contains 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 | |
type Goaled interface { | |
Goaled() bool | |
} | |
type Sane interface { | |
Sane() bool | |
} | |
type saneGoaled struct{goaled Goaled} | |
func (sg *saneGoaled) Sane() bool { | |
return !sg.goaled.Goaled() | |
} | |
func main() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapters in Go
fooer_bad.go fails to compile:
fooer_dumb.go compiles but has a dumb pointless adapter type.
Is there a more graceful solution to adapters in Go?