-module( geometry1).
-export([ test/ 0, area/ 1]).
test() ->
12 = area({ rectangle, 3, 4}),
144 = area({ square, 12}),
tests_worked.
area({ rectangle, Width, Height}) -> Width * Height;
area({ square, Side}) -> Side * Side.
area({ circle, Radius}) -> 3.14159 * Radius * Radius;
abstract class Shape {
abstract double area();
}
class Circle extends Shape {
final double radius;
Circle( double radius) { this.radius = radius; }
double area() { return Math.PI * radius* radius; }
}
class Rectangle extends Shape {
final double ht;
final double width;
Rectangle( double width, double height) {
this.ht = height;
this.width = width;
}
double area() { return width * ht; }
}
class Square extends Shape {
final double side;
Square( double side) {
this.side = side;
}
double area() { return side * side; }
}
"If you compare the Erlang code with Java code, you’ll see that in the Java program the code for area is in three places. In the Erlang program, all the code for area is in the same place."
Armstrong, Joe (2013-09-23). Programming Erlang: Software for a Concurrent World (Pragmatic Programmers) (p. 49). Pragmatic Bookshelf. Kindle Edition.