A sealed trait controlling a class hierarchy
The complete source of structure_shapes.ek9, compiled by the EK9 compiler. Shown on structure.html.
#!ek9 defines module site.structure.shapes defines trait ShapeLimit allow only Ellipse, Circle, Rectangle, Square, Triangle printDrawing() -> message as String //method body stdout <- Stdout() stdout.println(message) defines class Shape with trait of ShapeLimit as abstract draw() as abstract Ellipse extends Shape as open override draw() printDrawing("Ellipse") Circle extends Ellipse override draw() printDrawing("Circle") Rectangle extends Shape override draw() printDrawing("Rectangle") Triangle extends Shape override draw() printDrawing("Triangle") Square extends Shape override draw() printDrawing("Square") defines program DrawShapes() for shape in [Ellipse(), Circle(), Rectangle(), Square(), Triangle()] shape.draw()
Output
Ellipse Circle Rectangle Square Triangle