October 2015
Beginner to intermediate
400 pages
14h 44m
English
A type satisfies an interface if it possesses all the methods
the interface requires.
For example, an *os.File satisfies io.Reader, Writer,
Closer, and ReadWriter.
A *bytes.Buffer satisfies Reader, Writer,
and ReadWriter, but does not satisfy Closer
because it does not have a Close method.
As a shorthand, Go programmers often say that a concrete type “is a”
particular interface type, meaning that it satisfies the interface.
For example, a *bytes.Buffer is an io.Writer; an
*os.File is an io.ReadWriter.
The assignability rule (§2.4.2) for interfaces is very simple: an expression may be assigned to an interface only if its type satisfies the interface. So:
var w io.Writer w = os.Stdout ...