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.
Exercises
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 one
Pick the IDIOMATIC composite-literal syntax to construct a
04
fill blanks
Type the SINGLE WORD that goes in the blank to embed
05
fill blanks
When 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 program
Demonstrate method override via embedding. Build:
09
write a program
Theme 7.2 capstone — interface satisfaction via embedded