Pass 2 of Design

As I start coding, I begin with the Square class. Right away, I realize I forgot to define the constructor of the class in my OMT design. I know it will need a Container, so I'll just add that for now. I also realize that I didn't define any of the instance variables for the Square class. Hmmm, perhaps I did not think this through well enough. Also, if I create a subclass of FilledRectangle, I should probably specify a size that it should be drawn. The size of a square is something that should probably be defined as a constant. Does that mean I should have an interface containing my constants? 4 lines of code, and I already realize I probably should have planned a little better.

Okay, I'll go work out my OMT diagram a little better, so it's more complete.

So, there are probably some constants that I should define. I'll put them into a Constants class. I'll need to define the size of the Squares, so I'll make a SQUARE_SIZE constant. The size of the board is generally defined by a constant as well. But there are multiple board sizes. I guess I'll make constants for each of Beginner, Intermediate, and Advanced levels.

So, that reminds me, how will I set up the size of the board? Well, the Board class can be instantiated with a specified size. That way, an Advanced board would just be passed in a different size. There isn't really a need to create subclasses of Board for each of the difficulty levels, since they don't do anything different. They just have a different size.

So, if a user wants to play a different game, a new Board class is created. Wait a sec, if the Board is getting changed, what is keeping track of it? I guess I'll need a class that manages the game in general. I'll call that Game. So, I'll add that class. Oh, I also need a subclass of GP.Containers.Applet in order for the game to start. So I'll add that as well. I really should have given the design a little more thought before I tried to jump into coding.

So, the Applet will contain the Game, and the Game will contain a Board. That sounds good.

So, I was going to add the constructor to Square. What does it need? Well, it definitely needs a reference to a GP.Container. Oh. I guess that means the Board should be a subclass of Container. That would make sense. I'll add that. So Square needs a container. Board will also need a container, and I also decided it will need to specify a size. Game will also need to be constructed with a Container, so it can pass it on to Board.

The square should also keep track if it's covered or flagged. So, those will require two booleans. The EmptySquare subclass will also need an int to keep track of the number of neighbors it has.

So, this is looking a little better. Let's see what i can do with this.

New and improved OMT diagram

Code written


Last modified: Wed Mar 11 03:19:01 EST 1998