diff --git a/collects/htdch/draw/World.java b/collects/htdch/draw/World.java index f64a83f3d5..c5ac14881f 100644 --- a/collects/htdch/draw/World.java +++ b/collects/htdch/draw/World.java @@ -1,7 +1,7 @@ package draw; public abstract class World { - protected Canvas theCanvas = new SillyCanvas(600,600); // can I do better here? + protected Canvas theCanvas = new SillyCanvas(600,600); // can I do better than null here? /** *@author Matthias Felleisen, Kathy Gray diff --git a/collects/htdch/draw/design-note.txt b/collects/htdch/draw/design-note.txt new file mode 100644 index 0000000000..205764e2b9 --- /dev/null +++ b/collects/htdch/draw/design-note.txt @@ -0,0 +1,44 @@ + [Mon Aug 13 20:03:56 EDT 2007] + + + +1. SillyClass exists to get around the NULL problem in World.java. + + I create a SillyCanvas, which is a 600 x 600 canvas so that + theCanvas doesn't have to be initialized to NULL. + + A SillyCanvas is a Canvas that displays a warning for every + draw method that is invoked. So students can show the canvas + before they call bigBang and test the draw method in World, + but it is pretty silly. + + Rationale: + The reason I don't want NULL in this draw.* library is that + it is used with ProfessorJ's Beginner and Intermediate + language levels and they don't include NULL. It turns out, + however, that this particular NULL for theCanvas could "leak + out" if a student did this: + + new SampleWorld().theCanvas.show() + + or something less direct than that. + +2. Of course, the rationale also suggests that I may have made + a mistake in the design of World. Instead of creating World + via a no-argument constructor, I add a constructor of two + arguments, width and height, and force students to perform + a super call: + + World(int width, int height) { + this.theCanvas = new Canvas(width,height); + } + + World() { + throw RuntimeException("can't create a world without size arguments"); + } + + PRO: And voli`a, the problem would go away. + CONS: Students must fix the size of the canvas at World creation time. + With my existing design, they can choose different sizes when + they run bigBang. Is it worth it? Probably not. +