typeover
curriculum

Curriculum Idioms & ecosystem Embedding exercise 2 · mcq

Embedding

Animal has a method Describe() string. Dog embeds Animal (type Dog struct { Animal; Breed string }). What does method promotion mean for Dog?

TypeScript reference
Pick the idiomatic Go translation

About this theme

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.