5 ms·
The interface just defines the methods an object must have to be passed into this function. No types have to "implement" the interface in the traditional sense
by NateDad 14y ago
The interface just defines the methods an object must have to be passed into this function. No types have to "implement" the interface in the traditional sense. Anything that happens to have the same methods as are on the interface may be passed into the method that requires that interface.
Basically, the interface just defines at compile time what Python defines at runtime... except it's a hell of a lot easier to see what methods are required for a Go interface, than it is to see what methods are required for a python function (you basically have to read the entire function and any function that function passes the argument to).
Not that I don't like python, I do.