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.
Ilja, is correct - C++/COM circles use a specific term for this kind of composition:
Object Containment and Delegation 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.
Interestingly even the C++ community which has multiple implementation inheritance available prefers Containment/Delegation over non-polymorphic inheritance (i.e. protected and private inheritance).
Uses and Abuses of Inheritance, Part 1 Uses and Abuses of Inheritance, Part 2 [ May 22, 2007: Message edited by: Peer Reynders ]