-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearn.go
57 lines (46 loc) · 1.13 KB
/
learn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// structs are types
package main
import "fmt"
type Counter struct {
number int
}
var bigDigits = [][]string{
{" 000 ",
" 0 0 ",
"0 0",
"0 0",
"0 0",
" 0 0 ",
" 000 "},
{" 1 ", "11 ", " 1 ", " 1 ", " 1 ", " 1 ", "111"},
{" 222 ", "2 2", " 2 ", " 2 ", " 2 ", "2 ", "22222"},
}
// need to understand difference between make and new
// pointer and ampersand for getting location
func main() {
// newCounter := new(Counter)
// var anotherPointer *Counter
// anotherPointer = newCounter
// anotherPointer.number = 20
// fmt.Println(newCounter.number)
for row := range bigDigits[0] {
fmt.Println(row)
}
}
// interfaces can ONLY operate on non-pointers
// so must be strict type: variables are values; pointers are the address in memory --it does not return a value
// so you can't do this:
// func (c *Counter) Increment(someValue int) int {
// ...
// }
type CounterInterfae interface {
Increment(somevalue int) int
}
// attache it to Counter
// receivers?
// mutator methods?
func (c Counter) Increment(someValue int) int {
c.number += someValue
fmt.Println(c.number)
return c.number
}