mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 23:08:34 +08:00
fix typo for 10.2.md
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## 10.2.1 结构体工厂
|
||||
|
||||
Go 语言不支持面向对象编程语言中那样的构造子方法,但是可以很容易的在 Go 中实现 “构造子工厂“ 方法。为了方便通常会为类型定义一个工厂,俺惯例,工厂的名字以 new 或 New 开头。假设定义了如下的 File 结构体类型:
|
||||
Go 语言不支持面向对象编程语言中那样的构造子方法,但是可以很容易的在 Go 中实现 “构造子工厂“ 方法。为了方便通常会为类型定义一个工厂,按惯例,工厂的名字以 new 或 New 开头。假设定义了如下的 File 结构体类型:
|
||||
|
||||
```go
|
||||
type File struct {
|
||||
@@ -19,7 +19,7 @@ func NewFile(fd int, name string) *File {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &File(id, name)
|
||||
return &File(fd, name)
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user