reorganize: interfaces section
This commit is contained in:
@ -14,6 +14,9 @@ type game struct {
|
||||
price float64
|
||||
}
|
||||
|
||||
// be consistent:
|
||||
// if another method in the same type has a pointer receiver,
|
||||
// use pointer receivers on the other methods as well.
|
||||
func (g *game) print() {
|
||||
fmt.Printf("%-15s: $%.2f\n", g.title, g.price)
|
||||
}
|
||||
@ -27,8 +30,7 @@ func (g *game) discount(ratio float64) {
|
||||
|
||||
// PREVIOUS CODE:
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// + `g` is a copy: `discount` cannot change the original `g`.
|
||||
// func (g game) discount(ratio float64) {
|
||||
// func (g *game) discount(ratio float64) {
|
||||
// g.price *= (1 - ratio)
|
||||
// }
|
||||
|
Reference in New Issue
Block a user