Chapter 6 Methods 293 obtains the Graphicsobject for
Chapter 6 Methods 293 obtains the Graphicsobject for you and invokes another method, called update. Method updateinvokes method paintand passes to it the Graphicsobject. The repaint method is discussed in detail in Chapter 18, Multimedia. 6.17 (Optional Case Study) Thinking About Objects: IdentifyinClass Operations In the Thinking About Objects sections at the ends of Chapters 3, 4 and 5, we performed the first few steps in the object-oriented design for our elevator simulator. In Chapter 3, we identified the classes we need to implement. In Chapter 4, we created a class diagram that models the structure of our system. In Chapter 5, we examined objects states and modeled objects activities and state transitions. In this section, we concentrate on determining the class operations (or behaviors) needed to implement the elevator simulator. In Chapter 7, we concentrate on the collaborations (interactions) between objects of our classes. An operation of a class is a service that the class provides to clients (users) of that class. Consider the operations of some real-world classes. A radio s operations include setting its station and volume (typically invoked by a person adjusting the radio s controls). A car s operations include accelerating (invoked by the driver pressing the accelerator pedal), decelerating (invoked by the driver pressing the brake pedal and/or releasing the gas pedal), turning and shifting gears. We can derive many of the operations of each class directly from the problem statement. To do so, we examine the verbs and verb phrases in the problem statement. We then relate each of these to particular classes in our system (Fig. 6.20). Many of the verb phrases in Fig. 6.20 help us determine the operations of our classes. Class Verb phrases Elevator moves to other floor, arrives at a floor, resets elevator button, rings elevator bell, signals its arrival, opens its door, closes its door ElevatorShaft turns off light, turns on light, resets floor button Person walks on floor, presses floor button, presses elevator button, rides elevator, enters elevator, exits elevator Floor [none in the problem statement] FloorButton requests elevator ElevatorButton closes elevator door, signals elevator to move to opposite floor FloorDoor signals person to enter elevator (by opening) ElevatorDoor signals person to exit elevator (by opening), opens floor door, closes floor door Bell [none in the problem statement] Light [none in the problem statement] ElevatorModel creates person Fig. 6.2020 Verb phrases for each class in simulator. Fig. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01