This commit is contained in:
chai2010
2016-01-02 21:17:21 +08:00
parent 8772a9c000
commit ba03c527c0
17 changed files with 63 additions and 29 deletions

View File

@@ -6,16 +6,15 @@
在早些的章節中我們已經使用了標準庫提供的一些方法比如time.Duration這個類型的Seconds方法
```
const day = 24 * time.Hour
fmt.Println(day.Seconds()) // "86400"
```Go
const day = 24 * time.Hour
fmt.Println(day.Seconds()) // "86400"
```
併且在2.5節中我們定義了一個自己的方法Celsius類型的String方法:
```go
func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }
```Go
func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }
```
在本章中OOP編程的第一方面我們會向你展示如何有效地定義和使用方法。我們會覆蓋到OOP編程的兩個關鍵點封裝和組合。