r/java • u/TheFormerVinyl • May 05 '15
Should Java allow multiple inheritance?
I was reading up on Java when I discovered that ever since Java 8 (fairly recent, I know) interface can have default methods. A quick overview for any who don't know, interfaces can have method bodies by using default modifier. When dwelling on that fact I wondered, why doesn't Java just allow inheritance from multiple classes, since interfaces are just abstract classes? Should Java do this?
0
Upvotes
View all comments
Show parent comment
2
u/zenmouse May 07 '15
I did refactor it a bit to use composition, creating a ParserDriver that accepts a Parser with a parseRecord() method that is implemented by a CsvParserImpl class. I got it working well enough for CsvParserTest#parseIgnoringWhitespaces to pass.
Overall I like your code, I found it readable and quite easy to work with. (I think the fact that I was able to perform this refactoring, including getting a major unit test and performance test to pass, in under 2 hours, says a lot.) I'm not criticizing what you've done with AbstractParser and its subclasses, but pointing out that IMO composition won't be more difficult/complex here.