Created
April 25, 2018 01:59
-
-
Save kaneshin/46be21fd6b0e06ab24f84926adf00d24 to your computer and use it in GitHub Desktop.
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 | |
import "fmt" | |
type Member int | |
type Male Member | |
type Female Member | |
const ( | |
male Member = iota | |
female | |
) | |
func NewMale() Male { | |
return Male(male) | |
} | |
func NewFemale() Female { | |
return Female(female) | |
} | |
type MemberInterface interface { | |
Say() | |
} | |
func (m Member) Gender() string { | |
if m == male { | |
return "Male" | |
} | |
if m == female { | |
return "Female" | |
} | |
return "Neutral" | |
} | |
func (m Male) Say() { | |
fmt.Printf("%s, 男性振る舞い\n", Member(m).Gender()) | |
} | |
func (m Female) Say() { | |
fmt.Printf("%s, 女性振る舞い\n", Member(m).Gender()) | |
} | |
func Print(m MemberInterface) { | |
m.Say() | |
} | |
func main() { | |
Print(NewMale()) | |
Print(NewFemale()) | |
NewMale().Say() | |
NewFemale().Say() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment