Last active
September 24, 2019 03:08
-
-
Save fengyfei/85042bff520045777d9d414d1af6d4c2 to your computer and use it in GitHub Desktop.
[Go][Struct][Selector] Collection
This file contains hidden or 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 Sample interface { | |
Any() | |
Some() | |
} | |
type PartI struct { | |
} | |
func (p *PartI) Any() { | |
fmt.Println("PartI::Any()") | |
} | |
type PartII struct { | |
} | |
func (p *PartII) Some() { | |
fmt.Println("PartII::Some()") | |
} | |
type PartIII struct { | |
} | |
func (p *PartIII) Any() { | |
fmt.Println("PartIII::Any()") | |
} | |
func (p *PartIII) Some() { | |
fmt.Println("PartIII::Some()") | |
} | |
type Collection struct { | |
PartI | |
// PartIII | |
PartII | |
} | |
func main() { | |
c := &Collection{ | |
PartI{}, | |
// PartIII{}, | |
PartII{}, | |
} | |
c.Any() | |
c.Some() | |
} | |
/* | |
package main | |
import ( | |
"fmt" | |
) | |
type Sample interface { | |
Any() | |
Some() | |
} | |
type PartI struct { | |
} | |
func (p *PartI) Any() { | |
fmt.Println("PartI::Any()") | |
} | |
type PartII struct { | |
} | |
func (p *PartII) Some() { | |
fmt.Println("PartII::Some()") | |
} | |
type PartIII struct { | |
} | |
func (p *PartIII) Any() { | |
fmt.Println("PartIII::Any()") | |
} | |
func (p *PartIII) Some() { | |
fmt.Println("PartIII::Some()") | |
} | |
type Collection struct { | |
PartI | |
p PartIII | |
PartII | |
} | |
func main() { | |
c := &Collection{ | |
PartI{}, | |
PartIII{}, | |
PartII{}, | |
} | |
c.Any() | |
c.Some() | |
c.p.Any() | |
c.p.Some() | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment