mmcgrana / gobyexample

Go by Example
https://gobyexample.com
7.16k stars 1.26k forks source link

Shorten interface explanation #536

Closed kkeian closed 3 months ago

kkeian commented 3 months ago

The explanation for embedding a struct which implements an interface is confusing. The code for it restricts the container variable to one method: describe.

The example code in this patch uses the describer interface to specify a contract between a function and it's caller. This explicitly gives a practical reason for using struct embedding or adding a method to an already embedded struct.