reorganize: interfaces section

This commit is contained in:
Inanc Gumus
2019-08-21 20:38:38 +03:00
parent 8cb42216e4
commit c282da3c6d
27 changed files with 126 additions and 20 deletions

View File

@ -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)
// }