Go supports embedding of structs and interfaces
to express a more seamless composition of types.
This is not to be confused with |
|
|
|
|
|
|
|
|
|
A |
|
|
|
When creating structs with literals, we have to initialize the embedding explicitly; here the embedded type serves as the field name. |
|
We can access the base’s fields directly on |
|
Alternatively, we can spell out the full path using the embedded type name. |
|
Since |
|
|
|
Embedding structs with methods may be used to bestow
interface implementations onto other structs. Here
we see that a |
|
|
Next example: Generics.