go接口使用案例晓demo

1.go里面接口必须使用interface 这个案例也体现了多台特性

package main

import "fmt"

type Usb interface {
	work()
	finish()
}
type Phone struct {

}
func ( phone Phone) work(){
	fmt.Println("phone is working");
}
func (phone Phone) finish(){
	fmt.Println("phone is finish");
}
type Camera struct {

}
func(ca Camera) work(){
	fmt.Println("camera is workding");
}
func (ca Camera) finish(){
	fmt.Println("camera is finish");
}

type Computer struct {

}
func (com Computer) start(usb Usb){
	usb.work();
	usb.finish();
}
func main(){
	com:=Computer{};
	phone:=Phone{};
	com.start(phone);
}

  

上一篇:c++中队列(queue)的用法


下一篇:8-13 Just Finish it up uva11093