go interface composing interfaces type conversion implementing with values vs .pointers best prcatices

in wikipied what is interface
communicate unrelated object

Gopher china

abtract types
concrete type

memory layout
behavior attacherd to data through methods

describle behavior

the define a set of methods,withour specifi revi

abstratatrion

union of interface
two style

Go proverbs

why do we use interface

writ generic algorit
hindin details
providing interceprion points

func Writer

the bigger the interface the weaker the abstration

be conservative in waht you be ,be liberak ub waht you accept
TCP
call dispatch

Abstract Data Types

Mathmaticak model for data tyoe
defined

Go中的接口(interface)不描述数据,它只描述行为,它指定了一个类型(Type)的行为。定义一个interface,使用关键字type和interface,

type Write interface{
write([]byte) (int, error)
}

Type ConsoleWriter struct {}
和其他语言不同,Go不提供显示implement接口的关键字,而是通过给ConsoleWriter类型绑定一个和接口一样签名的方法来隐式的impelement接口。

func (cw ConsoleWriter) Write (data []byte) (int, error){
    n,err:==fmt.println(string(data))
    return n,err

}

命名规则,

composing interfaces

type conversion

the empty interface

type switches

implementing with values vs .pointers

best prcatices