Teachpacks for How to Design Classes

# An Imperative Drawing Library (HtDC)

###

This `idraw` package provides stateful classes and imperative methods for a visual world. Here is its class diagram of public fields and methods:

    import colors.*;
    import geometry.*;

      +---------------------------------+
      | abstract World                  |
      +---------------------------------+       +------------------------------------+
      | Canvas theCanvas                |------>| Canvas                             |
      +---------------------------------+       +------------------------------------+
      | void bigBang(int,int,double)    |       +------------------------------------+
      | World endOfTime()               |       | void show()                        |
      | World endOfWorld()              |       | void close()                       |
      | abstract void onTick()          |       | void drawCircle(Posn,int,Color)    |
      | abstract void onKeyEvent(String)|       | void drawDisk(Posn,int,Color)      |
      | abstract void draw()            |       | void drawRect(Posn,int,int,Color)  |
      | abstract void erase()           |       | void drawLine(Posn,Posn,Color)     |
      +---------------------------------+       | void drawString(Posn,String)       |
                                                | void clearCircle(Posn,int,Color)   |
                                                | void clearDisk(Posn,int,Color)     |
                                                | void clearRect(Posn,int,int,Color) |
                                                | void clearLine(Posn,Posn,Color)    |
                                                +------------------------------------+

The abstract `World` class in `idraw` provides the same methods as the `World` class in the `draw` library. Their return values are usually `void`, however, except for `endOfTime` and `endOfWorld`, which continue to return the last world.

In an analogous manner, the methods in the `Canvas` class export the same methods as the `Canvas` class in the `draw` package. Their return values, however, are `void`.