add: interfaces assertion and composition (wip)

This commit is contained in:
Inanc Gumus
2019-08-20 19:03:57 +03:00
parent aa7fada2aa
commit 6b95995c81
14 changed files with 397 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
package main
// usually: include the time method in the list.go
// it is here for clarity
// TODO: NEW
// you could include a time method in the book and game instead.
// but sometimes it is not possible to do so.
func (l list) time() (total int) {
for _, it := range l {
switch it := it.(type) {
case *game:
total += it.playTime
case book:
total += it.readTime
}
}
return total
}