Creating New Fish Subclasses

Refactor the Fish class, following the instructions below, then implement at least two of the following Fish subclasses. Develop test plans to test your new classes. (Be sure to view the testing suggestions at the end of this document.) Document your classes in the comments at the top and in internal comments as appropriate.




Refactor Fish

Several of the subclasses below involve finding a set of possible move locations and then randomly choosing one to move to. The current nextLocation method does this, but it combines aspects of the two. Refactor the nextLocation method to separate these two ideas:




Fish Subclass Options (choose at least two)




Testing Suggestions

As you design your Fish subclasses, be sure to consider "weird" conditions as well as obvious ones. For example, what will a fish do if it's in a corner, facing one of the two edges? What will it do if it is along an edge but not in a corner? What if it is completely surrounded with fish? The four scenarios below are examples of the kind of "boundary conditions" you should always remember to test.

       F  ~  ~  ~       ~  ~  F  ~       ~  n  ~  ~
       ~  ~  ~  ~       F  ~  ~  ~       n  F  n  ~
       ~  ~  ~  ~       ~  ~  ~  F       ~  n  ~  ~
       ~  ~  ~  ~       ~  F  ~  ~       ~  ~  ~  ~
  

You might want to make objects of each new subclass a different color, just as Pat did for darters, just to help you identify the different types as you test the simulation. You may also want to develop an initial configuration file that contains a mixture of Fish and subclass objects.



Alyce Brady, Kalamazoo College