Scenario

[Previous] [Next]

NASA has hired you to build a spacecraft flight simulator that will be used to train astronauts how to maneuver in various atmospheric conditions. Learning to fly in the actual spacecraft would be impractical mainly because each spacecraft costs billions of dollars to manufacture and millions of dollars to maintain. Improper handling of the spacecraft could lead to structural damage, which could cost further millions of dollars to fix. A flight simulator is a cost-effective and practical alternative.

Environmental conditions such as weather patterns, temperature, and various forms of matter inside and outside the earth's atmosphere affect the state of the spacecraft. The maneuvering capabilities of the spacecraft change depending on its state. Because the factors affecting state and the variances in maneuverability are numerous, you decide to implement the State design pattern to manage all the possible changes in maneuvering behavior caused by state conditions. The class diagram in Figure 12-1 clearly depicts the design. The flight simulator can start up in any initial state (such as Sunny Day Maneuvering or Hurricane Maneuvering). After startup, the simulator simulates an atmospheric change such as reentering the earth's atmosphere, which causes strong gravitational pull and ship contact with oxygen. These changes are manifested in the HullIntegrity property value, which affects the state of the spacecraft as determined by the SpacecraftStateManager object. As a result, the behavior of the methods IgniteThruster, Break, and Steer will dynamically change because of the intelligent state transition functionality implemented in the SpacecraftStateManager object that will in effect change the ISpacecraft implementation at run time. In this design, the Flight Simulator application is oblivious to the State design pattern; it is simply referencing an object that supports the ISpacecraft interface. Read on for in-depth coverage of the State design pattern.

click to view at full size.

Figure 12-1. The Flight Simulator application can effectively implement the State design pattern to create a scalable simulator that dynamically changes behavior based on external factors that affect its state.



Microsoft Visual Basic Design Patterns
Microsoft Visual Basic Design Patterns (Microsoft Professional Series)
ISBN: B00006L567
EAN: N/A
Year: 2000
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net