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.
9 ready
01
pick oneThe Go community phrase is: **"accept interfaces, return
02
pick one fmt.Stringer is the most common one-method interface in
03
pick onePick the IDIOMATIC interface signature for a function that
04
fill blanksType the method name that makes a type implement
05
fill blanksType 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 programTheme 7.5 capstone — "accept interfaces" in action. Define