# 接口实现（隐式）

URL: https://caijiao.org/go/03-structured/07-interface-impl
Source: docs/go/03-structured/07-interface-impl.md
Description: 本节介绍 Go 语言中接口的隐式实现机制，强调无需显式声明即可满足接口。

Go 语言接口的实现是隐式的，不需要显式声明。

## 1. 隐式实现

只要类型实现了接口定义的所有方法，就自动实现该接口，无需额外声明。

```go
type Reader interface {
    Read(p []byte) (n int, err error)
}

type File struct{}

func (f File) Read(p []byte) (n int, err error) {
    // 实现读取逻辑
    return 0, nil
}

// File 自动实现了 Reader 接口
````

## 2. 优点

* 简化代码，无需在类型声明时绑定接口
* 支持面向接口编程，提高灵活性
* 可以实现接口的多态

## 3. 使用示例

```go
var r Reader = File{}
n, err := r.Read(make([]byte, 10))
```

---

隐式实现接口使 Go 语言设计简洁灵活，方便扩展与复用。
