Type-Dependent Behavior/Control-Driven Programming/Static Dispatch

In UW 2.0 there will be different types of characters: elves, robots, knights, etc.

Character types are represented as objects:

Based on type, the attack method dynamically dispatches to a private helper method: uw2/Tournament.java

Problem: Dumb Good, Smart Bad

The problem with this design is that the Character class is too smart. It knows too much. It knows about all of the subclasses of characters, which means when a new subclass is added, we will have to update the attack method of the Character class (by adding a new condition.)

If there are many "smart" classes, then each will need to be updated. Forgetting to update one can lead to very obscure bugs.

Of course all of this assumes we have permission to modify the smart classes. Often we don't.