Output is:
Yellow is RED and GREEN
Cyan is BLUE and GREEN
Purple is RED and BLUE
Output is:
Yellow is RED and GREEN
Cyan is BLUE and GREEN
Purple is RED and BLUE
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| type Yellow interface { | |
| Red() string | |
| Green() string | |
| } | |
| type Cyan interface { | |
| Green() string | |
| Blue() string | |
| } | |
| type Purple interface { | |
| Red() string | |
| Blue() string | |
| } | |
| type RGB struct {} | |
| func (rgb *RGB) Red() string { | |
| return "RED" | |
| } | |
| func (rgb *RGB) Green() string { | |
| return "GREEN" | |
| } | |
| func (rgb *RGB) Blue() string { | |
| return "BLUE" | |
| } | |
| func Demo(yellow Yellow, cyan Cyan, purple Purple) { | |
| fmt.Println("Yellow is "+yellow.Red()+" and "+yellow.Green()) | |
| fmt.Println("Cyan is "+cyan.Blue()+" and "+cyan.Green()) | |
| fmt.Println("Purple is "+purple.Red()+" and "+purple.Blue()) | |
| } | |
| func main() { | |
| c := &RGB{} | |
| Demo(c, c, c) | |
| } | |