45 lines
1.5 KiB
Plaintext
45 lines
1.5 KiB
Plaintext
[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.
|
|
|