Skip to content

Instantly share code, notes, and snippets.

@suganoo suganoo/embeded.go
Created Feb 1, 2019

Embed
What would you like to do?
interfaceの確認
package main
import (
"fmt"
)
type BaseDownloader struct {
}
type BaseUploader struct {
}
func (d *BaseDownloader)download() {
fmt.Println("base download")
}
func (u *BaseUploader)upload() {
fmt.Println("base upload")
}
type ParserParent interface {
parse()
}
type BaseParser struct {
}
func (p *BaseParser)parse() {
fmt.Println("base parse")
}
type JSONParser struct {
}
type CSVParser struct {
}
func (p *JSONParser)parse() {
fmt.Println("JSONParser")
}
func (p *CSVParser)parse() {
fmt.Println("CSVParser")
}
type FileParser interface {
download()
parse()
upload()
}
type BaseComponent struct {
*BaseDownloader
ParserParent
*BaseUploader
}
func main() {
var fp FileParser
bc := BaseComponent{
&BaseDownloader{},
&BaseParser{},
&BaseUploader{},
}
fp = &bc
fp.download()
fp.parse()
fp.upload()
bcj := BaseComponent{
&BaseDownloader{},
&JSONParser{},
&BaseUploader{},
}
fp = &bcj
fp.download()
fp.parse()
fp.upload()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.