3 ms·
interfaces with default implementations? Doesn't this look like... multiple inheritance?
by ifdefdebug 11y ago
interfaces with default implementations? Doesn't this look like... multiple inheritance?
- the8472 11y agothey only add behavior based on other already-present methods, they don't add fields.
- ifdefdebug 11y agoRight, not adding fields makes all the difference.
- danieldk 11y agoYou can still not have member variables, so the default implementations can only be implemented in terms of other methods. So it should probably be classified as 'limited multiple inheritance'. It does have the diamond problem though.
- scott_s 11y agoThat was my immediate thought - this is closer to multiple inheritance, as it introduces the diamond problem: https://en.wikipedia.org/wiki/Multiple_inheritance#The_diamond_problem https://en.wikipedia.org/wiki/Multiple_inheritance#The_diamo... According to that page, Java forces programmers to resolve the ambiguity by making it a compiler error. A reasonable approach, I think. I've done more OO development in C++, and I've found this technique useful - putting a default implementation in a class which was mostly an interface because only a small number of subclasses needed specialized behavior.
- deleted 11y ago[deleted]
- mooreds 11y agoMy exact thought.
- incepted 11y agoMore like traits. Multiple inheritance of implementation is problematic because it allows parent classes to define state. Traits and Java 8's interfaces don't.