Just a simple language design related question here. In languages like Swift, in order for a struct/class to conform to a protocol/interface, one needs to explicitly declare it as such
struct Dog: Animal {
// implementation of Animal protocols here
}
But why is it that in Go, there are no explicit ways to show what interfaces a struct conforms to?
Isn't this just making things unclear or are there any other reasons behind it?
This allow to evolve to provide interface even for legacy types (which never explicitly declared respecting said interface)
If those types already provide the right methods (ie the same API as the one specified by your interface), they will satisfy that interface.
That allows to maintain a low coupling between those legacy types (which have no idea your interface exist) and your program, which accepts instances of that interface.
See "What are some examples of Go interfaces?"
Those quotes are from this 2012 article, and also from this thread, where you can read Rob Pike's comment: