01
Interfaces
A type never writing anywhere in the source that it satisfies an interface, and the small-interface principle being a consequence of this; the empty interface carrying type information into runtime and the cost of that; the question a type assertion and a type switch ask of a value; contract composition through embedding; the measurable counterpart of defining an interface on the consumer side.
- 01 The Interface Concept 4 of sixteen bindings are established in a declaration, 4 at a use site, 8 in the value — the course's binding split is produced here. The same type satisfies four interfaces and its source has zero references to any of them; the small-interface principle is not advice here but an observation measured by the count of satisfying types falling as method count rises. Limiting measurement: a compile-time conformance proof moves that same binding into the declaration, and the compiler stays silent when the proof is missing.
- 02 The Empty Interface and `any` The empty interface wants zero methods and every type satisfies zero methods: which type will arrive is never written in the source, and type information is carried inside the value. When the same value is carried by three separate static types, the dynamic type does not change; the cost is that anything placed in the value turns into a pair and cannot be called directly. Limiting measurement: when a nil pointer is placed in the empty interface, the interface itself is not nil.
- 03 Type Assertion and Type Switch Two of five values satisfy an interface; the type assertion's two-value form counts this without panicking, the single-value form panics when it fails, and the panic is only read as panic=true. A type switch distributes the same five values into its own branches. Limiting measurement: the same value can fit both a concrete-type branch and an interface branch, and the branch chosen depends on writing order — the lesson runs this with two orderings.
- 04 Interface Embedding Embedding combines two interfaces into a single composite contract in the source, and this combination adds no new method at all: the same contract, built once by embedding and once rewritten by hand, wants the same two methods. The minimum method count a type must write to satisfy the composite interface equals the total method count of the embedded interfaces, no more, no fewer. Limiting measurement: embedding only combines the contract, not the implementation — two separate types can each satisfy their own separate contract, yet neither satisfies the composite contract.
- 05 Interface Design Consumer-side definition is measured: a four-method type is written without referencing any interface at all, four separate consumers unaware of each other each define their own single-method interface, and the same type satisfies all four — the producer's source has zero references to any of these four names. Limiting measurement: when the same contract is defined under two separate names in two consumers, they appear unable to stand in for each other, yet the type system accepts both directly against the same value.