Created
February 1, 2019 10:01
-
-
Save suganoo/a098c0a4911c2e35415a83e719c4273c to your computer and use it in GitHub Desktop.
interfaceの確認
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 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