Contributed by Steve Dekorte
scribble = List clone // toss the different shapes into a collection scribble append(Rectangle clone setX(10) setY(20) setWidth(5) setHeight(6)) scribble append(Circle setX(15) setY(25) setRadius(8)) // Use the shapes polymorphically scribble foreach(s, s draw]; s rMoveToX(100) rMoveToY(100) s draw ) // call a rectangle specific function aRectangle = Rectangle clone setX(0) setY(0) setWidth(15) setHeight(15) aRectangle setWidth(30) aRectangle draw
Shape := Object clone do( x ::= 0 y ::= 0 rMoveToX := method(nx, x = x + nx) rMoveToY := method(ny, y = y + ny)
Rectangle := Shape clone do(
height ::= 0
width ::= 0
draw := method(
writeln("Drawing a Rectangle at:(", x, ",", y, ") width ", width, " height ", height)
)
Circle ::= Shape clone do(
radius ::= 0
draw := method(
printf("Drawing a Circle at:(", x, ",", y, "), radius ", radius)
)