Curriculum Idioms & ecosystem Embedding
Embedding
Struct embedding gives you composition without inheritance. Embed a type as an unnamed field and its methods get promoted onto the outer struct. This is how Go does "extend a type" — by containing one. The rule: prefer composition; Go literally doesn't give you inheritance to misuse.
9 ready
01
pick one Pick the line that EMBEDS the type Animal into the struct
02
pick one Animal has a method Describe() string. Dog embeds
03
pick onePick the IDIOMATIC composite-literal syntax to construct a
04
fill blanksType the SINGLE WORD that goes in the blank to embed
05
fill blanksWhen an outer type ALSO defines a method with the same
06
type one line Write the composite literal that constructs a Dog with
07
type one line Define the embedded type field for Dog. The scaffold has
08
write a programDemonstrate method override via embedding. Build:
09
write a programTheme 7.2 capstone — interface satisfaction via embedded