hi , the reason why we dont have multiple inheritance in java is it will defeat the basic logic -- Java is designed to be simple and Object Oriented. ofcourse multiple inheritance makes the code complex . but will it not be a pure oo concept . i m not sure how that could be . or i m wrong in my very basic understanding of multiple inheritance & java
expecting the answers thanks in advance ashok :roll:
Retaining multiple inheritance of interfaces allowed Java to leverage two advantages of MI: Interface( classe)s and ease of (polymorphic) Use. Many have lamented the lacking capability for "Combining Modules/Libraries" which is used for Mixins. It seems that in the Java domain this niche is being filled by Aspect-Oriented Programming (e.g. aspectj; Writing Mixins using AspectJ) - it has its own challenges.
hi thanks peer . ya i could understand that Diamond Problem has its own complexities . but there could be a chance when one class has to extend two other classes and use the two super class methods (functionalities) and it will add its own . i just want to know how this is achieved by multiple interface inheritance.i could not the simulate the above situation with multiple interface inheritance.
This is typically solved in Java by using composition instead. In my experience, most often this results in a better, more flexible design than MI would.
As an aside, "pure OO" doesn't have any meaningful definition I'm aware of.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by ashok ganesan: but there could be a chance when one class has to extend two other classes and use the two super class methods (functionalities) and it will add its own . i just want to know how this is achieved by multiple interface inheritance.
Originally posted by Ilja Preuss: This is typically solved in Java by using composition instead.
So given that you have an interface Z that is already implemented by class A and class B, you want to create class C that implements interface Z in terms of A and B. An instance of C creates its own instances of A and B (or has them injected from the outside) and calls their functions as necessary during its own implementation of Z. So C contains A and B and delegates to them when appropriate. In this particular scenario we inherit from a single interface but we have multiple implementations that are weaved together by the developer. Using Containment/Delegation you can always fake (multiple) implementation inheritance as long as you have multiple interface inheritance.