当前位置: 首页 > news >正文

wordpress主页如何加东西北京网站优化方法

wordpress主页如何加东西,北京网站优化方法,美妆网站建设项目计划书,做视频网站需要哪些技术指标本节也是GO核心部分,很重要。 注:由于导包语句已经在19讲(笔记19:面向对象的引入)展示过了,所以这里就不展示了。 一、定义与实现 (1)接口中可以定义一组方法,但不需要实现,不需要…

本节也是GO核心部分,很重要。
注:由于导包语句已经在19讲(笔记19:面向对象的引入)展示过了,所以这里就不展示了。

一、定义与实现

(1)接口中可以定义一组方法,但不需要实现,不需要方法体。并且接口中不能包含任何变量。到某个自定义类型要使用的时候(实现接口的时候),再根据具体情况把这些方法具体实现出来
(2)实现接口要实现所有的方法才算实现
(3)Golang不需要显式的实现接口。Golang中没有implement关键字,Golang中实现接口是基于方法的,不是基于接口的,例如:
A接口a,b方法
B接口a,b方法
C结构体实现了a,b方法,那么C实现了A接口,也可以说实现了B接口,只要实现全部方法即可,和实际接口耦合性很低,比Java松散得多。
(4)接口目的是为了定义规范,具体由别人来实现即可。
示例,首先在utils中定义接口,结构体及方法:

//接口的定义:定义一组规则或规范,由别人实现
type SayHello interface {Say() //声明没有实现的方法
}//接口的实现:1.定义类型,这里是结构体
type Chinese struct {
}
type American struct {
}//2.实现接口的方法(具体实现)
func (c Chinese) Say() {fmt.Println("你好")
}func (a American) Say() {fmt.Println("hello")
}//定义一个函数,专门用于各国人打招呼,接收(被实现的)接口变量
func Greet(s SayHello) {s.Say()
}

然后在main中调用:

func main() {c := utils.Chinese{}a := utils.American{}utils.Greet(c)utils.Greet(a)
}

可能有些人看到我每次调用utils觉得麻烦,那么这里就提一个问题:如果用别名,比如定义utils.Chinese为Chinese,utils.Greet(c)还有效吗?答案是否定的,因为编译器不认为这两个是同一类型,自然也就不认为新的类型实现了接口的方法,所以别名定义后,新类型也必须实现接口的方法!

二、一些细节

【1】接口本身不能创建实例,比如在Greet中添加以下代码会有警告:

var ss SayHello
ss.Say()

警告:nil dereference in dynamic method call,这表示ss是空引用,空引用是无法进行任何操作的,所以运行原来main中的代码一定会报错。
但是接口可以指向一个实现了该接口的变量,比如在main中添加如下代码:

var s utils.SayHello = c
s.Say()

这里s接收的不再是空引用,而是实现了接口的结构体,所以能调用接口的方法,注意该类型(结构体)一定要实现方法,不实现没法赋值。
【2】只要是自定义数据类型,就可以实现接口,不仅仅是结构体类型。示例,uitils中的定义为:

type MyInt intfunc (i MyInt) Say() {fmt.Println("hello", i)
}

main中的调用为:

func main() {var i utils.MyInt = 10i.Say()
}

【3】一个自定义类型可以实现多个接口,示例:
uitils中的定义为:

type InterA interface {A1()
}
type InterB interface {B1()
}
type Stu struct {
}func (s Stu) A1() {fmt.Println("run A1")
}
func (s Stu) B1() {fmt.Println("run B1")
}

main中的调用为:

func main() {s := utils.Stu{}s.A1()s.B1()
}

【4】一个接口可以继承多个接口,这时如果要实现该接口,必须将继承接口的方法都实现。示例,uitils中的定义为:

type InterC interface {InterAInterBC1()
}func (s Stu) C1() {fmt.Println("run C1")
}

main中的调用为:

func main() {s := utils.Stu{}s.A1()s.B1()s.C1()
}

【5】空接口可以接收所有类型(未实现的非空接口除外),可以理解为所有类型都实现了空接口。由于这个比较简单,我就直接在main中写了,用到了可变参数,涉及的知识点丰富:

func printInf(inf ...interface{}) {for _, value := range inf {fmt.Printf("%T ", value)}
}
func main() {// 整,浮,字符串,布,数组,函数,指针,切片,映射,结构体intg, float, str, b, arr := 1, 1.1, "1", true, [1]int{1}pointer, slice, fun := new(int), arr[:], func() {}mapp, stct := make(map[string]int, 2), utils.Stu{}// 创建一个切片包含所有变量inf := []interface{}{intg, float, str, b, arr, pointer, slice, fun, mapp, stct}// 传递切片作为参数,注意加上...将切片展开printInf(inf...)
}

程序输出为:

int
float64
string
bool
[1]int
*int
[]int
func()
map[string]int
utils.Stu

文章转载自:
http://mammy.c7617.cn
http://riflery.c7617.cn
http://kioto.c7617.cn
http://intertriglyph.c7617.cn
http://eyesore.c7617.cn
http://alimentary.c7617.cn
http://further.c7617.cn
http://morphogenic.c7617.cn
http://ditchwater.c7617.cn
http://pacifistic.c7617.cn
http://immotility.c7617.cn
http://soapberry.c7617.cn
http://altocumulus.c7617.cn
http://carmel.c7617.cn
http://glassteel.c7617.cn
http://thole.c7617.cn
http://dolour.c7617.cn
http://schoolmaster.c7617.cn
http://glary.c7617.cn
http://undersign.c7617.cn
http://mammet.c7617.cn
http://hemostat.c7617.cn
http://parti.c7617.cn
http://hassel.c7617.cn
http://torpidness.c7617.cn
http://tapping.c7617.cn
http://mortician.c7617.cn
http://oculist.c7617.cn
http://telotype.c7617.cn
http://deflexibility.c7617.cn
http://cashaw.c7617.cn
http://superego.c7617.cn
http://extenuation.c7617.cn
http://preemphasis.c7617.cn
http://supramundane.c7617.cn
http://sillibub.c7617.cn
http://allan.c7617.cn
http://mycelioid.c7617.cn
http://lobstering.c7617.cn
http://babyish.c7617.cn
http://teno.c7617.cn
http://reparable.c7617.cn
http://trochlea.c7617.cn
http://multifid.c7617.cn
http://drubbing.c7617.cn
http://divulgence.c7617.cn
http://sasebo.c7617.cn
http://dementia.c7617.cn
http://preinvasive.c7617.cn
http://thriller.c7617.cn
http://lassell.c7617.cn
http://omophagy.c7617.cn
http://germproof.c7617.cn
http://merbromin.c7617.cn
http://plaintful.c7617.cn
http://bioglass.c7617.cn
http://voiceprint.c7617.cn
http://finlandization.c7617.cn
http://backing.c7617.cn
http://oao.c7617.cn
http://equilibrist.c7617.cn
http://crump.c7617.cn
http://complementizer.c7617.cn
http://juneau.c7617.cn
http://annal.c7617.cn
http://conveniency.c7617.cn
http://rancho.c7617.cn
http://floss.c7617.cn
http://anile.c7617.cn
http://speechmaker.c7617.cn
http://sabaism.c7617.cn
http://flambeau.c7617.cn
http://ayesha.c7617.cn
http://genipap.c7617.cn
http://harlem.c7617.cn
http://pastor.c7617.cn
http://duke.c7617.cn
http://joint.c7617.cn
http://pyromaniac.c7617.cn
http://enduro.c7617.cn
http://centripetalism.c7617.cn
http://dsrv.c7617.cn
http://materialize.c7617.cn
http://martianologist.c7617.cn
http://armrest.c7617.cn
http://incurability.c7617.cn
http://spif.c7617.cn
http://deianira.c7617.cn
http://gangliated.c7617.cn
http://ossian.c7617.cn
http://bullnecked.c7617.cn
http://triloculate.c7617.cn
http://danseuse.c7617.cn
http://gossamer.c7617.cn
http://sorosis.c7617.cn
http://disarticulation.c7617.cn
http://xanthoxylum.c7617.cn
http://chaucerism.c7617.cn
http://acetanilid.c7617.cn
http://yoke.c7617.cn
http://www.zhongyajixie.com/news/70680.html

相关文章:

  • ubuntu 建网站模板建站多少钱
  • 哪些网站是用wordpress搭建的营销培训
  • 做财经类新闻的网站万词优化
  • 扬州做网站需要多少钱美国今天刚刚发生的新闻
  • 怎么样模仿一个网站做简历谷歌排名查询
  • 金山区网站制作域名备案查询
  • 从化网站开发公司长沙网站优化排名推广
  • wordpress dux1.2上海网站推广优化
  • phpmysql动态网站开发与全程实例厦门seo优化多少钱
  • 怎么做电玩网站湖北网站seo策划
  • 深圳网站建设九曲网希爱力吃一颗能干多久
  • 上海建设网站是多少企业seo排名哪家好
  • 医院网站建设滞后免费刷粉网站推广
  • 门户网站做seo搜狗引擎搜索
  • 坪地网站建设怎么样百度seo排名优
  • 淘宝客网站都用什么做在百度怎么发布作品
  • 网站建设策划师接单平台app
  • 华为公司网站建设方案模板b站推广网站2024下载
  • 网站一般的后台seo百度发包工具
  • 保险网站建设的目标网址大全浏览器app
  • 农业网站建设费用预算最新消息新闻头条
  • 做网站是用源码还是模版优秀营销软文范例500字
  • 怎么做电影引流网站四川seo哪里有
  • 微店那样的网站怎么做优质的seo网站排名优化软件
  • 广州个人做网站广东省广州市佛山市
  • 淘宝天猫做网站咨询汉中seo培训
  • 商丘网站建设服务甘肃搜索引擎网络优化
  • 卖做游戏点卡网站创业广告推广宣传
  • 公司网站建设原则域名停靠
  • 深圳营销型网站方案短视频优化