Mid-term exam, question 3-a (Linearization)

ddimitrov
Erstie
Erstie
Beiträge: 20
Registriert: 17. Jul 2015 16:28

Mid-term exam, question 3-a (Linearization)

Beitrag von ddimitrov »

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?!

TBA
Neuling
Neuling
Beiträge: 10
Registriert: 20. Okt 2009 18:10

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von TBA »

Probably because HP does not implement the set method.

ddimitrov
Erstie
Erstie
Beiträge: 20
Registriert: 17. Jul 2015 16:28

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von ddimitrov »

TBA hat geschrieben:Probably because HP does not implement the set method.
DHWS does not implement it as well, but inherits it. :( Do I miss something?

FabianG
Erstie
Erstie
Beiträge: 14
Registriert: 22. Okt 2012 00:05

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von FabianG »

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:

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)
}
The result i get is:

Code: Alles auswählen

set: DoubleHashedWithSalt
set: Salt
set: HashedPassword
set: Hash
set: Password = -1588597053
-1588597053
Regards

TBA
Neuling
Neuling
Beiträge: 10
Registriert: 20. Okt 2009 18:10

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von TBA »

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.

FabianG
Erstie
Erstie
Beiträge: 14
Registriert: 22. Okt 2012 00:05

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von FabianG »

TBA hat geschrieben:Well, that is not the code from the exam. You added a set method to DoubleHashWithSalt and HashedPassword...
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...

ddimitrov
Erstie
Erstie
Beiträge: 20
Registriert: 17. Jul 2015 16:28

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von ddimitrov »

Thank you for the clarification and the good example :D
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.
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.

Boddlnagg
Mausschubser
Mausschubser
Beiträge: 54
Registriert: 10. Dez 2012 12:07

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von Boddlnagg »

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.

ddimitrov
Erstie
Erstie
Beiträge: 20
Registriert: 17. Jul 2015 16:28

Re: Mid-term exam, question 3-a (Linearization)

Beitrag von ddimitrov »

Boddlnagg 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.
Very good explanation. Thank you :)

Antworten

Zurück zu „Archiv“