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

fix bug in solution 4.3: use def not val in trait #74

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

russHyde
Copy link
Contributor

Exercise 4.1.4.3 Shaping Up 2 (Da Streets) had a bug.
Using the code as it existed meant that

new Square(2.0).perimeter

was 0.0 (instead of 8.0)

This occurred because the override val perimeter = 2 * ... was evaluated at the definition of trait Rectangular, rather than after creation of a new Square object. The definition of perimeter and area should have used def or lazy val; the preceding text recommended using def within traits. Hence the change.

Exercise 4.1.4.3 Shaping Up 2 (Da Streets) had a bug.
Using the code as it existed meant that 

`new Square(2.0).perimeter`

was 0.0 (instead of 8.0)

This occurred because the `override val perimeter = 2 * ...` was evaluated at the definition of trait Rectangular, rather than after creation of a new Square object. The definition of `perimeter` and `area` should have used `def` or `lazy val`; the preceding text recommended using `def` within `traits`. Hence the change.
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

Successfully merging this pull request may close these issues.

1 participant