Structural typing determines interface compatibility from the methods a type provides. In Go, no explicit implementation declaration is required, and the compiler verifies satisfaction before execution. section 5.5
This supports practical abstractions: formatting can depend on String(), while measurement types become interchangeable when they provide ToImperial() and ToMetric(). section 5.5
// --- Convertible Interface ---
type Convertible interface {
ToImperial() Measurement
ToMetric() Measurement
}
A Convertible interface specifies the method shape that metric and imperial measurement types must provide. section 5.5
Measurement conversion
MetricWeight, ImperialWeight, MetricVolume, and ImperialVolume can satisfy Convertible through matching conversion methods, allowing conversion code to work against the interface rather than a concrete type. section 5.5
