-
Notifications
You must be signed in to change notification settings - Fork 1
/
interfaces.slide
49 lines (29 loc) · 936 Bytes
/
interfaces.slide
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
Interfaces
23 Feb 2018
Adrian Lanzafame
@LanzafameAdrian
* Interfaces
Interfaces in Go provide a way to specify the behavior of an object: if something can do this, then it can be used here.
Distinction between an interface type and an interface value:
// Pusher is an interface type.
type Pusher interface {
Push()
}
// p is an empty interface value.
var p interface{}
.link https://play.golang.org/p/xf0F5MOM5r2
* Behaviour not State
Example of OOP-like type hierarchies:
.link https://play.golang.org/p/r6to0aMm6I
Example of grouping by behaviour:
.link https://play.golang.org/p/yOj1zJCRlj
* Composition
Example of interface composition:
.link https://play.golang.org/p/s7B4mmIvtj
* Internals of an Interface
What is an interface value?
.image interfaces/interface-internal.png
* Rule of Thumb
_Accept_interfaces,_return_structs._
.caption Jack Lindamood