Newer
Older
01_hello / interface / interface3.go
yhornisse on 2 Oct 2021 376 bytes add sample
package main

import "fmt"

type Piyo struct {
	Name string
}

type Hoge interface {
	Foo()
}

type Fuga interface {
	Bar()
}

type Parent interface {
	Hoge
	Fuga
}

func (p *Piyo) Foo() {
	fmt.Println("foo")
	fmt.Println(p)
}

func (p *Piyo) Bar() {
	fmt.Println("bar")
	fmt.Println(p)
}

func baz(p Parent) {
	p.Foo()
	p.Bar()
}

func main() {
	v := Piyo{"hoge"}
	baz(&v)
}