|
|
|
|
|
by fiddlerwoaroof
3162 days ago
|
|
What’s the difference between an abstract class and a Java-style interface in a language that allows multiple inheritance? I’ve generally thought of interfaces as a way to get some of the features of multiple inheritance while preventing the parts of multiple inheritance that cause issues (e.g. the diamond problem). However, these days, every language I know of that has single inheritance+interfaces allows interfaces (or traits, in the case of PHP) to specify default implementations of their methods. |
|
In concrete terms for C++, this means that abstract base classes Must be defined before the objects are defined. So if I wanted to use a library, I would be entirely restricted to whatever abstract base classes they define.
For Go, I could use a library and then define whatever interfaces I needed specifically for the functions I want to implement. Its effectively a much more structured and rigorous architecture for templated code.
At least this is my understanding. I've explored Go just enough to get some of the higher level concepts but I haven't quite dug into it yet. So correct me if I'm wrong.