This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path11-interfaces.slide
More file actions
57 lines (32 loc) · 1.54 KB
/
11-interfaces.slide
File metadata and controls
57 lines (32 loc) · 1.54 KB
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
Interfaces in Go
22 Feb 2017
Tags: edmontongo, golang, workshop
Brett McKay
* What are interfaces?
Most collections are defined by the type of data they hold.
Interfaces are defined by the behaviour they demand.
What do you think is meant by that?
* Declare an interface
.code 11-interfaces/interface.go /DECLARE_BEGIN OMIT/,/DECLARE_END OMIT/
What behaviour does this interface demand?
* Satisfying Interfaces
.code 11-interfaces/interface.go /IMPLEMENT_BEGIN OMIT/,/IMPLEMENT_END OMIT/
* Using Interfaces
.play -edit 11-interfaces/interface.go /USE_BEGIN OMIT/,/USE_END OMIT/
* Empty Interface
.code 11-interfaces/interface.go /EMPTY_BEGIN OMIT/,/EMPTY_END OMIT/
What does a type need to implement in order to satisfy the above interface?
Can you think of a reason to use this interface?
* Documention and Interfaces
An example of something that uses an interface
.link https://golang.org/pkg/net/http/#Client.Post Post
Definiton of
.link https://golang.org/pkg/io/#Reader Reader
Things that implement Reader
.link https://golang.org/pkg/bytes/#Buffer.Read ByteBuffer
.link https://golang.org/pkg/os/#File.Read File
* Exercise
.link https://golang.org/pkg/fmt/#Stringer Stringer
- What is the output when you print a struct and a struct pointer?
- After implementing the Stringer inteface for your struct with a value receiver. What is the output when you print a struct and a struct pointer?
- After implementing the Stringer interface for your struct with a pointer receiver. What is the output when you print a struct and a struct pointer?