Mid-term exam, question 3-a (Linearization)
Mid-term exam, question 3-a (Linearization)
Hi everybody,
the linearization of 3-a is {DHWS, S, HP, H, P}, but the super call for the set method is DHWS,S,H,P. Why is HP missing when it is a part of the linearization? Or I did write it down wrong from the black board?!
the linearization of 3-a is {DHWS, S, HP, H, P}, but the super call for the set method is DHWS,S,H,P. Why is HP missing when it is a part of the linearization? Or I did write it down wrong from the black board?!
Re: Mid-term exam, question 3-a (Linearization)
Probably because HP does not implement the set method.
Re: Mid-term exam, question 3-a (Linearization)
DHWS does not implement it as well, but inherits it.TBA hat geschrieben:Probably because HP does not implement the set method.

Re: Mid-term exam, question 3-a (Linearization)
Hey,
how do you know, that HashedPassword is not part of set's call chain? I was curious about this as well, so i added some printing to the different set methods and the result was as expected imho. Here is the code i used for that, maybe i did something wrong there:
The result i get is:
Regards
how do you know, that HashedPassword is not part of set's call chain? I was curious about this as well, so i added some printing to the different set methods and the result was as expected imho. Here is the code i used for that, maybe i did something wrong there:
Code: Alles auswählen
abstract class Password {
private[this] var password = "password"
def getPw: String = { return password }
def set(pwd: String) = {println("set: Password = "+pwd); password = pwd }
}
trait Hash extends Password {
abstract override def set(pwd: String) = { println("set: Hash"); super.set(pwd.hashCode.toString) }
}
trait Salt extends Password {
val salt = "xyz"
abstract override def set(pwd: String) = { println("set: Salt"); super.set(salt + pwd) }
}
class HashedPassword extends Password with Hash {
override def set(pwd: String) = { println("set: HashedPassword"); super.set(pwd) }
}
class DoubleHashWithSalt extends HashedPassword with Salt with Hash {
override def set(pwd: String) = { println("set: DoubleHashedWithSalt"); super.set(pwd) }
}
object Main2 extends App {
val dhws = new DoubleHashWithSalt
dhws.set("lala")
println(dhws.getPw)
}
Code: Alles auswählen
set: DoubleHashedWithSalt
set: Salt
set: HashedPassword
set: Hash
set: Password = -1588597053
-1588597053
Re: Mid-term exam, question 3-a (Linearization)
Well, that is not the code from the exam. You added a set method to DoubleHashWithSalt and HashedPassword... Therefore I would say the set method is called in this order: Salt, Hash, Password.
Re: Mid-term exam, question 3-a (Linearization)
Yes of course, however i just wanted to show that (if implemented) the order would indeed be the same as the linearization path. Since there are implementations missing in the linearization path (in the exam's code) these will of course be skipped. I figure that it sometimes helps (at least myself) to have some kind of visual proof of some sort to get these kind of things into your brain...TBA hat geschrieben:Well, that is not the code from the exam. You added a set method to DoubleHashWithSalt and HashedPassword...
Re: Mid-term exam, question 3-a (Linearization)
Thank you for the clarification and the good example

I would also say that the call order is Salt -> Hash -> Password, but on the review of the mid-term exam, the solution was DHWS -> S -> H -> P. That's why i was confused, because DHWS doesn't implement set as well but is part of the super call chain.TBA hat geschrieben:Well, that is not the code from the exam. You added a set method to DoubleHashWithSalt and HashedPassword... Therefore I would say the set method is called in this order: Salt, Hash, Password.
Re: Mid-term exam, question 3-a (Linearization)
Salt -> Hash -> Password was also considered a correct solution in the exam (it's what I wrote), and it definitely makes more sense to me, since DHWS is not really part of the super call chain if you call the method on an instance of DHWS (DHWS is this, not super). I think the solution was presented with DHWS included because the call chain starts with DHWS.
Re: Mid-term exam, question 3-a (Linearization)
Very good explanation. Thank youBoddlnagg hat geschrieben:Salt -> Hash -> Password was also considered a correct solution in the exam (it's what I wrote), and it definitely makes more sense to me, since DHWS is not really part of the super call chain if you call the method on an instance of DHWS (DHWS is this, not super). I think the solution was presented with DHWS included because the call chain starts with DHWS.
