Software Engineering
Home Planning Requirements Writing Hazard Analysis Requirement Analysis Config Control Software Design Software Testing Software Standards Basic Logic

Software Design Case Study - Sky Diving

The Problem

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:

  1. The skydiver arrives at the airport (Idle state).
  2. The parachute is prepared (Prep state).
  3. The parachutist boards the airplane (Boarding state).
  4. The airplane takes off (InFlight state).
  5. The parachutist jumps out of the plane (Falling state).
  6. The parachutist pulls the ripcord and lands safely (Landing state).

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.

Unit Testing

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.