update: interfaces lecture

This commit is contained in:
Inanc Gumus
2019-08-23 11:03:51 +03:00
parent 435c08e800
commit e0b2786fd9
3 changed files with 88 additions and 9 deletions

View File

@ -15,15 +15,13 @@ func main() {
rubik = puzzle{title: "rubik's cube", price: 5}
)
// thanks to the printer interface we can add different types of values
// to the list.
//
// only rule: they need to implement the `printer` interface.
// to do that: each type needs to have a print method.
var store list
store = append(store, &minecraft, &tetris, mobydick, rubik)
tetris.discount(.8)
// printer(tetris).discount(.8)
store.print()
// p can store a value of any type that has a `print()` method
var p printer
p = puzzle{title: "sidewinder", price: 10}
p.print()
}
}