Files
the-way-to-go_ZH_CN/eBook/11.2.md
leisore 94b7740f84 Merge branch 'master' of https://github.com/Unknwon/the-way-to-go_ZH_CN.git
Conflicts:
	eBook/10.8.md
	eBook/11.0.md
	eBook/11.1.md
	eBook/directory.md
2015-09-07 16:01:52 +08:00

553 B

11.2 接口嵌套接口

一个接口可以包含一个或多个其他的接口,这相当于直接将这些内嵌接口的方法列举在外层接口中一样。

比如接口 File 包含了 ReadWriteLock 的所有方法,它还额外有一个 Close() 方法。

type ReadWrite interface {
    Read(b Buffer) bool
    Write(b Buffer) bool
}

type Lock interface {
    Lock()
    Unlock()
}

type File interface {
    ReadWrite
    Lock
    Close()
}