I think the answer to this question needs to a more retrospective approach towards the grammar, and how would implement it through software engineering. (Excuse the over simplification)
First a quick flashback of what are types
?
They are just memory blocks with compiler logic on top. What makes an array
different from a string
is what the compiler allows us to do with those memory blocks. (Think deeper and you may begin to realize the true difference between strongly typed
and dynamically typed
languages.)
Now next you need to realize that pointers are their own types per say.
*variable
is a different memory block (aka type) than variable
. It's just that the compiler always assumes that content of *variable
is always going to be an address to a memory block of type to the right of the declaration along with other restriction/features it imposes.
Then let's recap what an interface is.
Pseudo-scientific definition: A set of requirements for any first class citizen to be of a specific type.
Translated to software engineering- any block of memory (types) that has the same memory structure (think back to structure packing) associated to it as described in a contract (interface
) can be passed around as with the type name that the contract mentions.
Now you may begin to realize that when you say
func (f *Faz) Bar() string
is f
's block of memory holding a function, where f
's type is a pointer to Faz
where areas
func (f Faz) Bar() string
is f
's block of memory, where f
's type is Faz
So when you are saying that a variable of *Faz
type is satisfying a contract, then how can you assume that a variable of Faz
type will qualify as interface type in the code? Chose who satisfies your contract, and only that type can assume the interface type in your code.
MyFoo
that implementBar
should have pointer receivers, or all of them must. That's a different issue than @0xor1 was having, but others might find this question because they are mixing their receiver types (like I was) and not understanding the error they're getting. - Hephaestus