Let me explain my observation in scala about multiple inheritance-
Multiple inheritance is not possible in scala for classes. I can understand this is due to "Diamond Problem" http://stackoverflow.com/questions/2064880/diamond-problem
so below code does not compile
class High {
def confuse(){
println("High::I will confuse you later")
}
}
class MiddleLeft extends High {
override def confuse(){
println("MiddleLeft::I will confuse you later")
}
}
class MiddleRight extends High{
override def confuse(){
println("MiddleRight::I will confuse you later")
}
}
// Below code does not compile
class LowLeft extends MiddleRight with MiddleLeft{
def calConfuse(){
confuse()
}
}
Now traits might have concrete classes. But it supports multiple inheritance because order of how traits are extended does matter which solve the diamond problem , so below code works properly
trait High {
def confuse(){
println("High::I will confuse you later")
}
}
trait MiddleLeft extends High {
override def confuse(){
println("MiddleLeft::I will confuse you later")
}
}
trait MiddleRight extends High{
override def confuse(){
println("MiddleRight::I will confuse you later")
}
}
class LowLeft extends MiddleRight with MiddleLeft{
def calConfuse(){
confuse()
}
}
class LowRight extends MiddleLeft with MiddleRight{
def calConfuse(){
confuse()
}
}
object ConfuseTester extends App{
val lowLeft:LowLeft=new LowLeft()
lowLeft.confuse() //prints>>>MiddleLeft::I will confuse you later
val lowRight:LowRight=new LowRight()
lowRight.confuse()//prints>>>MiddleRight::I will confuse you later
}
My question is why multiple inheritance for classes does not follow same strategy like trait does(Ordering of how those are extended)