Curriculum Idioms & ecosystem The small-interface idiom
The small-interface idiom
io.Reader { Read(p []byte) (n int, err error) }. One method. Go interfaces are typically tiny because implicit satisfaction rewards it — small interfaces are easy to satisfy accidentally, which is good. The community phrase: "accept interfaces, return structs." Funcs take the smallest interface they need.
Exercises
9 ready
01
pick one
The Go community phrase is: **"accept interfaces, return
02
pick one
fmt.Stringer is the most common one-method interface in
03
pick one
Pick the IDIOMATIC interface signature for a function that
04
fill blanks
Type the method name that makes a type implement
05
fill blanks
Type the keyword that starts an interface declaration
06
type one line
Define the Stringer interface — one method, `String()
07
type one line
Write the String() method on Tag so that t.String()
08
write a program
Build a Point type that satisfies fmt.Stringer and
09
write a program
Theme 7.5 capstone — "accept interfaces" in action. Define