March 2002
Intermediate to advanced
496 pages
8h 51m
English
The code for Door_1 is somewhat complex because the use of the state variable is spread throughout the class. In addition, you might find it difficult to compare the state transition methods, particularly click(), with the state machine in Figure 22.1. The STATE pattern can help you to simplify this code. To apply STATE in this example, make each state of the door a separate class, as Figure 22.3 shows.

The refactoring that Figure 22.3 shows uses the Door_2 class to contain the context of the state machine. A ...
Read now
Unlock full access