这个有点新鲜哟。。。

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 {
	user
	level 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() {
	ad := admin {
		user:  user {
			name: "john smith",
			email: "john@yahoo.com",
		},
		level: "super",
	}

	sendNotification(&ad)
	ad.user.notify()
	ad.notify()

}

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

  

最新文章

  1. Win10提示没有权限使用网络资源问题解决
  2. MVP模式(Android)
  3. qt qml ajax 获取 json 天气数据示例
  4. NOIp 2013 #3 转圈游戏 Label:模拟
  5. JQuery兼容IE6问题汇总(不断更新)
  6. 详解Python对象属性
  7. (int),Int32.Parse() 和 Convert.toInt32() 的区别
  8. Linux信号(signal) 机制分析
  9. HTTP基础:URL格式、 HTTP请求、响应、消息
  10. python学习第十一天 -- 函数式编程
  11. jQuery 1.9+ ajaxStart事件无效,无法被触发的原因。
  12. (简单) LightOJ 1074 Extended Traffic,SPFA+负环。
  13. STL中的二分查找———lower_bound,upper_bound,binary_search
  14. [51nod1673]树有几多愁
  15. eclipse版本对应的jdk版本
  16. 定时调度系列之Quartz.Net详解
  17. Node.js_ express.Router 路由器_模块化管理路由
  18. redis----------基本命令使用
  19. k8s中yaml文常见语法
  20. Objective-C市场占有率排名升至第4位

热门文章

  1. linux安装mysql之设置远程访问权限
  2. 【WebService】——契约优先
  3. mysqli DB封装
  4. Oracle中SQL语言介绍以及基本用法
  5. 批处理之FOR命令
  6. 在程序内部跳转到下一个页面 和 向另一个servlet发起跳转
  7. 【题解】SDOI2008莎拉公主的困惑
  8. 【考试记录】4.8 Path (网络流 —— 劲题)
  9. Python之利用reduce函数求序列的最值及排序
  10. BZOJ2729 [HNOI2012]排队 【高精 + 组合数学】