github.com/l3x/learn-fp-go@v0.0.0-20171228022418-7639825d0b71/2-design-patterns/ch04-solid/03_car/src/car/car.go (about)

     1  package car
     2  
     3  import "fmt"
     4  
     5  type Car struct {
     6  	Make string
     7  	Model string
     8  }
     9  func (c Car) Tires() int { return 4 }
    10  func (c Car) PrintInfo() {
    11  	fmt.Printf("%v has %d tires\n", c, c.Tires())
    12  }
    13  
    14  type CarWithSpare struct {
    15  	Car
    16  }
    17  func (o CarWithSpare) Tires() int { return 5 }
    18  
    19  func (c CarWithSpare) PrintInfo() {
    20  	fmt.Printf("%v has %d tires\n", c, c.Tires())
    21  }
    22  //func (c CarWithSpare) PrintInfo(upCase bool) {
    23  //	if upCase {
    24  //		fmt.Printf("%v HAS %d TIRES\n", c, c.Tires())
    25  //	} else {
    26  //		fmt.Printf("%v has %d tires\n", c, c.Tires())
    27  //	}
    28  //}