Files
learngo/interfaces/composition/main.go

58 lines
1.2 KiB
Go
Raw Normal View History

// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
2019-08-27 15:21:17 +03:00
import (
2019-08-30 00:49:27 +03:00
"encoding/json"
2019-08-27 15:21:17 +03:00
"fmt"
)
func main() {
2019-08-27 15:21:17 +03:00
store := list{
2019-08-30 00:49:27 +03:00
&book{product{"moby dick", 10}, 118281600},
&book{product{"odyssey", 15}, "733622400"},
&book{product{"hobbit", 25}, nil},
&puzzle{product{"rubik's cube", 5}},
&game{product{"minecraft", 20}},
&game{product{"tetris", 5}},
&toy{product{"yoda", 150}},
2019-08-27 15:21:17 +03:00
}
2019-09-02 19:07:24 +03:00
out, _ := json.MarshalIndent(store, "", "\t")
2019-08-30 00:49:27 +03:00
fmt.Println(string(out))
2019-09-02 19:07:24 +03:00
// store.discount(.5)
// fmt.Print(store)
2019-08-30 00:49:27 +03:00
2019-09-02 19:07:24 +03:00
// var (
// nilItem item
// nilBook *book
// )
2019-08-30 00:49:27 +03:00
2019-09-02 19:07:24 +03:00
// fmt.Println("nilBook ?", nilBook == nil)
// fmt.Println("nilItem?", nilItem == nil)
2019-08-30 00:49:27 +03:00
2019-09-02 19:07:24 +03:00
// nilItem = nilBook
// fmt.Println("nilItem?", nilItem == nil)
2019-08-27 15:21:17 +03:00
2019-09-02 19:07:24 +03:00
// books := store[:3]
2019-08-27 15:21:17 +03:00
2019-09-02 19:07:24 +03:00
// books.discount(.5)
// fmt.Printf("%s\n", store)
2019-08-27 15:21:17 +03:00
2019-09-02 19:07:24 +03:00
// others := store[3:]
// sort.Sort(byPrice(others))
// fmt.Printf("\n%s\n", store)
2019-08-27 15:21:17 +03:00
2019-09-02 19:07:24 +03:00
// store = list{books, others}
// fmt.Printf("\n%s\n", store)
// // sort.Sort(sort.Reverse(byPrice(store)))
// sort.Sort(byName(store))
}