Skip to content

Commit 5c6a58b

Browse files
committed
tweak
1 parent 8e54cdc commit 5c6a58b

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/main/scala/s4j/scala/chapter18/HeroConstructorPatternExample.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ package s4j.scala.chapter18
1818

1919
object HeroConstructorPatternExample extends App {
2020

21-
val bruce = new SuperHero("Batman", "Bruce Wayne", List("Intellect", "Speed", "Agility", "Strength"))
22-
val youngBruce = new Person("Bruce Wayne")
21+
val bruce = new SuperHero("Batman", "Bruce Wayne", List("Speed", "Agility"))
22+
val steve = new SuperHero("Captain America", "Steve Rogers", List("Tactics", "Speed"))
2323
val jane = new Person("Jane Doe")
2424

25+
2526
def superPowersFor(person: Person) = {
2627
person match {
27-
case SuperHero(_, name, powers) => powers
28-
case _ => List()
28+
case SuperHero(_, _, powers) => powers
29+
case _ => List()
2930
}
3031
}
3132

32-
// Example of a constructor pattern
33+
// What super-powers does an otherwise unknown person have, if they are a
34+
// superhero with the alter-ego Bruce Wayne?
3335

34-
// What super powers does a person have, if they are in fact a super hero who's alter ego is Bruce Wayne?
35-
val person = bruce
36-
println("Bruce has the following powers " + superPowersFor(person))
37-
println("Young Bruce has the following powers " + superPowersFor(youngBruce))
38-
println("Jane has the following powers " + superPowersFor(jane))
36+
println("Bruce has the following powers: " + superPowersFor(bruce).mkString(", "))
37+
println("Steve has the following powers: " + superPowersFor(steve).mkString(", "))
38+
println("Jane has the following powers: " + superPowersFor(jane).mkString(", "))
3939
}

0 commit comments

Comments
 (0)