Skip to content

Instantly share code, notes, and snippets.

@vvviiimmm
Last active February 19, 2017 19:24
Show Gist options
  • Select an option

  • Save vvviiimmm/921893cfdf0e68b488c37397fd336dbc to your computer and use it in GitHub Desktop.

Select an option

Save vvviiimmm/921893cfdf0e68b488c37397fd336dbc to your computer and use it in GitHub Desktop.
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