Last active
February 19, 2017 19:24
-
-
Save vvviiimmm/921893cfdf0e68b488c37397fd336dbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trait Shape { | |
| def area: Double | |
| } | |
| case class Circle(radius: Double) | |
| case class Rectangle(width: Double, length: Double) | |
| // v (no constructor parameters) | |
| class CircleShape extends Shape { | |
| override def area : Double = ??? // radius? | |
| } | |
| // v (no constructor parameters) | |
| class RectangleShape extends Shape { | |
| override def area: Double = ??? // width and height? | |
| } | |
| def areaOf(shape: Shape): Double = shape.area | |
| areaOf(new CircleShape) | |
| areaOf(new RectangleShape) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment