它是否具有非接口称为“* er” [英] Is it idiomatic having non-interfaces called like "*er"
问题描述
Effective Go指出:
按照惯例,单方法接口用方法名加上
an -er后缀或类似修饰来构造代理名词:
Reader
,Writer
,Formatter
,CloseNotifier
等。
bufio.io
包包含:
// Reader为io.Reader对象实现缓冲。
类型Reader结构{
buf []字节
rd io.Reader
r,w int
err错误
lastByte int
lastRuneSize int
它是否具有像* er这样的结构?特别是在这种情况下,它是一个 struct
,与 io.Reader
是同一个接口。
评论 type bufio.Reader struct
很重要:
// 包装 既然 从用户的角度来看,它是一个 The "Effective Go" states: By convention, one-method interfaces are named by the method name plus
an -er suffix or similar modification to construct an agent noun:
Is it idiomatic having structs named like "*er"? Especially in this case it's a The comment // The bufio packages adds: It wraps an Since For the user's point of view, it is a 这篇关于它是否具有非接口称为“* er”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Reader
为
io.Reader
对象实现缓冲。
io.Reader
或 io.Writer
对象,创建另一个对象( Reader
或 Writer
)缓冲和文本I / O的一些帮助。
bufio.Reader
没有添加任何新服务,但只是以缓冲方式实现 io.Reader
,保留名称并仅实现函数是有意义的:a struct
就足够了。
Reader
,他/她可以在需要io.Reader的地方使用。
Reader
, Writer
, Formatter
, CloseNotifier
etc.bufio.io
package contains this:// Reader implements buffering for an io.Reader object.
type Reader struct {
buf []byte
rd io.Reader
r, w int
err error
lastByte int
lastRuneSize int
}
struct
with the same name as io.Reader
which is an interface.type bufio.Reader struct
are important:Reader
implements buffering for an io.Reader
object.
io.Reader
or io.Writer
object, creating another object (Reader
or Writer
) that also implements the interface but provides buffering and some help for textual I/O. bufio.Reader
isn't there to add any new service, but only to implements an io.Reader
in a buffered way, it makes sense to keep the name and just implement the functions: a struct
is enough.Reader
that he/she can uses wherever an io.Reader is required.