3 ms·
Something like this: https://go.dev/play/p/AVVz0qs2i1e https://go.dev/play/p/AVVz0qs2i1e This is much less convenient than using interfaces directly when that
by jerf 2y ago
Something like this: https://go.dev/play/p/AVVz0qs2i1e https://go.dev/play/p/AVVz0qs2i1e
This is much less convenient than using interfaces directly when that is possible, but comes with a lot more power. You have more insight into the "interface" value, you can use this to manually implement prototype-like behavior as seen in Javascript, you can deliberately make an object where one "method" is invoked on one object and one "method" is invoked on another, which is hard to read but may be just what you need in some situation, etc.
There are a lot of ways to improvise on this tune.
Also note most OO or OO-flavored languages can do this, Go has no special claim to it. But the tradeoffs are pretty similar in all those languages... you want to be sure this is what you need before you use it, because the design costs are significant.