感觉比java玄幻啊~~~

package main

import (
	"fmt"
)




type notifier interface{
	notify()
}


type user struct {
	name  string
	email string
}

func (u *user) notify() {
	fmt.Printf("Sending user email to %s<%s>\n",
		u.name,
		u.email)
}

type admin struct {
	name string
	email string
}

func (a *admin) notify() {
	fmt.Printf("Sending admin email to %s<%s>\n",
		a.name,
		a.email)
}


//main is the entry of the program
func main() {
	bill := user{"Bill", "[email protected]"}
	
	sendNotification(&bill)
	
	lisa := admin{"Bill", "[email protected]"}
	
	sendNotification(&lisa)

}

func sendNotification(n notifier) {
	n.notify()
}

  go语言多态接口样例

相关文章:

  • 2021-05-11
  • 2022-12-23
  • 2021-12-28
  • 2019-07-16
  • 2021-08-14
  • 2022-02-12
  • 2021-08-26
  • 2022-12-23
猜你喜欢
  • 2022-02-19
  • 2021-12-31
  • 2021-12-11
  • 2022-02-20
  • 2022-12-23
相关资源
相似解决方案