ch7: fix code format

This commit is contained in:
chai2010
2016-01-21 10:22:10 +08:00
parent 2420954025
commit 0b5ec941ed
13 changed files with 208 additions and 186 deletions

View File

@@ -1,4 +1,5 @@
## 7.3. 實現接口的條件
一個類型如果擁有一個接口需要的所有方法,那麽這個類型就實現了這個接口。例如,\*os.File類型實現了io.ReaderWriterCloser和ReadWriter接口。\*bytes.Buffer實現了ReaderWriter和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
}
```