fix: coding style and file format for chapter 10.

This commit is contained in:
Bo-Yi Wu
2017-02-11 12:28:43 +08:00
parent d9041c7fc3
commit ca79293078
19 changed files with 731 additions and 720 deletions

View File

@@ -1,40 +1,41 @@
package main
import "fmt"
type Base struct {
id string
}
func (b *Base) Id() string {
return b.id
}
func (b *Base) SetId(id string) {
b.id = id
}
type Person struct {
Base
FirstName string
LastName string
}
type Employee struct {
Person
salary float32
}
func main() {
idjb := Base{"007"}
jb := Person{idjb, "James", "Bond"}
e := &Employee{jb, 100000.}
fmt.Printf("ID of our hero: %v\n", e.Id())
// Change the id:
e.SetId("007B")
fmt.Printf("The new ID of our hero: %v\n", e.Id())
}
/* Output:
ID of our hero: 007
The new ID of our hero: 007B
*/
package main
import "fmt"
type Base struct {
id string
}
func (b *Base) Id() string {
return b.id
}
func (b *Base) SetId(id string) {
b.id = id
}
type Person struct {
Base
FirstName string
LastName string
}
type Employee struct {
Person
salary float32
}
func main() {
idjb := Base{"007"}
jb := Person{idjb, "James", "Bond"}
e := &Employee{jb, 100000.}
fmt.Printf("ID of our hero: %v\n", e.Id())
// Change the id:
e.SetId("007B")
fmt.Printf("The new ID of our hero: %v\n", e.Id())
}
/* Output:
ID of our hero: 007
The new ID of our hero: 007B
*/