Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

traits.md "shaping up with traits" #55

Open
tunesmith opened this issue Dec 11, 2017 · 0 comments
Open

traits.md "shaping up with traits" #55

tunesmith opened this issue Dec 11, 2017 · 0 comments

Comments

@tunesmith
Copy link

tunesmith commented Dec 11, 2017

The solution for Up 2 (Da Streets) didn't quite work for me. Minor note: I'm seeing that the Rectangle case class has "val"'s in the constructor. But as for the error, in Square, redefining width/height as val led to 0.0 results for area and perimeter. Keeping them as def's allowed them to calculate correctly:

@ case class Square(size: Double) extends Rectangular {
    val width = size
    val height = size
  }
defined class Square

@ val sq = Square(3)
sq: Square = Square(3.0)

@ sq.perimeter
res6: Double = 0.0

@ case class Square(size: Double) extends Rectangular {
  def width = size
  def height = size
  }
defined class Square

@ val sq = Square(3)
sq: Square = Square(3.0)

@ sq.perimeter
res9: Double = 12.0

@ sq.area
res10: Double = 9.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant