Struct embedding lets one Go struct type promote another type’s fields and methods. It provides reuse through composition rather than class-based inheritance: there is no superclass, type hierarchy, virtual dispatch, or implicit “is-a” relationship. section 1.5 section 5.2
Use struct embedding to:
- Compose larger domain types from simpler structs without maintaining an inheritance tree. section 1.5
- Promote fields and methods while adding domain-specific behavior around an existing type. section 5.6.1
- Combine embedding with interfaces so composed types can participate in flexible abstractions. section 5.7
Recipe measurements
A recipe application can embed a measurement type in metric and imperial measurement types, then add conversion or formatting behavior without changing the original measurement. Recipes can compose these measurements with ingredients and steps, scale them, convert them, and generate grocery lists. section 5.6.1 section 5.6.2
Figure 1.5 Inheritance vs. composition
Compare inheritance hierarchies with composition through embedded structs. section 1.5



