DEV Community

Discussion on: The Problem with Interfaces, and how Go Fixed it

Collapse
 
coreload profile image
📶

A type that implements an interface does so solely by using a value of that type in a position for that interfaces. So a use is a kind of implicit definition.

If a type is used in the position of two interfaces with some or all method signatures in common this should be 1. suspect or 2. based on informal contracts that those common methods are intended to conform to each other. Type safety will be enforced. Intent should be suspect.

Collapse
 
danielhoffmann_ profile image
Daniel HB

Interesting, so there is some type inference going on when you throw an object at a method that expects an Interface as an argument. Thanks for the explanation!

Thread Thread
 
kunde21 profile image
Chad Kunde

In the case of passing a struct into a function that takes an interface, the compiler enforces interface requirements. It will even tell you what methods are missing from the type which cause it not to fulfill the interface.