Software Design Case Study - Sky Diving
This problem was devised specifically to teach the principles of designing a Mealy state machine using the State Design Pattern. It was written in Java using Eclipse 3.3.
The software simulates a skydiving sequence. The normal flow is as follows:
This example uses several Design Patterns in addition to the State pattern. Concrete State objects are implemented as Flyweights, which allows them to be reused. This allows multiple state machines to exist without having to create additional State objects. Since they are Flyweights, all State context is held in the StateMachine class.
The user interface is incredibly simple and not very thrilling, as its purpose is to demonstrate the state machine design concepts, not create a video game. The UI has two instances of the state machine, to show that the Flyweight states have been correctly designed and that the StateMachine class correctly holds all the context. In addition, a few extra fun features have been added to demonstrate additional state machine concepts, such as Guards.
The state diagram was used as the basis for unit testing. For each state, each transition was tested to ensure that the correct events occurred. Each of the two state machines was exercised independantly to ensure that the state context was being correctly held within the appropriate state machine.