typeover
curriculum

Curriculum Idioms & ecosystem Embedding exercise 5 · fill-word

Embedding

When an outer type ALSO defines a method with the same name as a promoted one, the outer's method overrides. To call the inner's method explicitly, you go through the embedded type's NAME as a field path: d.${word}.Describe(). Type the field name you'd use.

TypeScript reference
Fill the blanks →

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.