Objects often characterized in different ways that are orthogonal to each other
For example, the instructor is
Cannot be placed into an inheritance hierarchy
CS Example - complex Numbers
Two abstract classifications:
Magnitude: things that can be compared to each other
Number: things that can perform arithmetic
Three specific classes:
Integer: comparable and arithmetic
Char: comparable but not arithmetic
Complex: arithmetic but not comparable
Solutions
1. make number subclass of magnitude, but redefine comparison
operators in class complex to print error message
- subclassing for limitations
2. Don't use inheritance at all - redefine all operators
in all classes
-flattening the inheritance
tree
3. Use inheritance for some relationships, but simulate
others - use Number, but have each number implement all relational operators
4. Make Number and Magnitude independent, have Integer
inherits from both
-multiple inheritance
Another example - walking Menus
What happens when same name is used to both parent classes?
Java supports Multiple inheritance of interfaces (subtypes) but not of classes (subclasses)
interface A { ... }
interface B { ... }
interface AB extends A, B { ... }
interface C { ... }
class X { ... }
class Y extends X implements AB, C { ... }