update: interfaces lecture
This commit is contained in:
@ -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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user