Then remove the "math" interface and the "result" function. This would result in less code for this example. But I guess interfaces are still useful if the code is more complex in this.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a clear example of the use of an interface. But, wouldn't it be easier just to replace these lines:
result(a) and result(b)
With these lines?
fmt.Println("Sum: ", a.sum(), "Substr: ", a.substr()) // Sum: 15 Substr: 5
fmt.Println("Sum: ", b.sum(), "Substr: ", b.substr()) // Sum: 30 Substr: 10
Then remove the "math" interface and the "result" function. This would result in less code for this example. But I guess interfaces are still useful if the code is more complex in this.