mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-10-17 20:42:50 +00:00
ch7: fix code format
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
## 7.3. 實現接口的條件
|
||||
|
||||
一個類型如果擁有一個接口需要的所有方法,那麽這個類型就實現了這個接口。例如,\*os.File類型實現了io.Reader,Writer,Closer,和ReadWriter接口。\*bytes.Buffer實現了Reader,Writer,和ReadWriter這些接口,但是它沒有實現Closer接口因爲它不具有Close方法。Go的程序員經常會簡要的把一個具體的類型描述成一個特定的接口類型。舉個例子,\*bytes.Buffer是io.Writer;\*os.Files是io.ReadWriter。
|
||||
|
||||
接口指定的規則非常簡單:表達一個類型屬於某個接口隻要這個類型實現這個接口。所以:
|
||||
@@ -112,29 +113,29 @@ Track
|
||||
|
||||
```go
|
||||
type Artifact interface {
|
||||
Title() string
|
||||
Creators() []string
|
||||
Created() time.Time
|
||||
Title() string
|
||||
Creators() []string
|
||||
Created() time.Time
|
||||
}
|
||||
```
|
||||
其它的一些特性隻對特定類型的文化産品才有。和文字排版特性相關的隻有books和magazines,還有隻有movies和TV劇集和屏幕分辨率相關。
|
||||
|
||||
```go
|
||||
type Text interface {
|
||||
Pages() int
|
||||
Words() int
|
||||
PageSize() int
|
||||
Pages() int
|
||||
Words() int
|
||||
PageSize() int
|
||||
}
|
||||
type Audio interface {
|
||||
Stream() (io.ReadCloser, error)
|
||||
RunningTime() time.Duration
|
||||
Format() string // e.g., "MP3", "WAV"
|
||||
Stream() (io.ReadCloser, error)
|
||||
RunningTime() time.Duration
|
||||
Format() string // e.g., "MP3", "WAV"
|
||||
}
|
||||
type Video interface {
|
||||
Stream() (io.ReadCloser, error)
|
||||
RunningTime() time.Duration
|
||||
Format() string // e.g., "MP4", "WMV"
|
||||
Resolution() (x, y int)
|
||||
Stream() (io.ReadCloser, error)
|
||||
RunningTime() time.Duration
|
||||
Format() string // e.g., "MP4", "WMV"
|
||||
Resolution() (x, y int)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -142,9 +143,9 @@ type Video interface {
|
||||
|
||||
```go
|
||||
type Streamer interface {
|
||||
Stream() (io.ReadCloser, error)
|
||||
RunningTime() time.Duration
|
||||
Format() string
|
||||
Stream() (io.ReadCloser, error)
|
||||
RunningTime() time.Duration
|
||||
Format() string
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user